@iyulab/chat-components 0.4.0 → 0.5.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.
Files changed (237) hide show
  1. package/CHANGELOG.md +124 -21
  2. package/README.md +133 -16
  3. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorate.js +9 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.122.0/helpers/decorateMetadata.js +6 -0
  5. package/dist/_virtual/_glob-assets_raw/intent-prompt.md.1907474e.js +4 -0
  6. package/dist/_virtual/_glob-assets_raw/view-prompt.md.e0dbcffe.js +4 -0
  7. package/dist/components/blocks/UCodeBlock.d.ts +24 -2
  8. package/dist/components/blocks/UCodeBlock.js +65 -2
  9. package/dist/components/blocks/UCodeBlock.styles.js +4 -4
  10. package/dist/components/blocks/UFileBlock.d.ts +33 -0
  11. package/dist/components/blocks/UFileBlock.js +154 -0
  12. package/dist/components/blocks/{UFilesBlock.styles.js → UFileBlock.styles.js} +12 -90
  13. package/dist/components/blocks/UJsonBlock.d.ts +44 -2
  14. package/dist/components/blocks/UJsonBlock.js +128 -3
  15. package/dist/components/blocks/UJsonBlock.styles.js +4 -4
  16. package/dist/components/blocks/UMarkedBlock.d.ts +44 -2
  17. package/dist/components/blocks/UMarkedBlock.js +154 -4
  18. package/dist/components/blocks/UMarkedBlock.styles.js +4 -4
  19. package/dist/components/blocks/URefBlock.d.ts +16 -2
  20. package/dist/components/blocks/URefBlock.js +58 -3
  21. package/dist/components/blocks/URefBlock.styles.js +4 -4
  22. package/dist/components/blocks/UTableBlock.d.ts +47 -2
  23. package/dist/components/blocks/UTableBlock.js +197 -4
  24. package/dist/components/blocks/UTableBlock.styles.js +4 -5
  25. package/dist/components/blocks/UTextBlock.d.ts +36 -2
  26. package/dist/components/blocks/UTextBlock.js +94 -4
  27. package/dist/components/blocks/UTextBlock.styles.js +4 -4
  28. package/dist/components/blocks/UThinkBlock.d.ts +30 -2
  29. package/dist/components/blocks/UThinkBlock.js +86 -4
  30. package/dist/components/blocks/UThinkBlock.styles.js +4 -4
  31. package/dist/components/blocks/UToolBlock.d.ts +19 -2
  32. package/dist/components/blocks/UToolBlock.js +68 -3
  33. package/dist/components/blocks/UToolBlock.styles.js +4 -4
  34. package/dist/components/buttons/UAttachButton.d.ts +21 -2
  35. package/dist/components/buttons/UAttachButton.js +61 -3
  36. package/dist/components/buttons/UAttachButton.styles.js +4 -4
  37. package/dist/components/buttons/UCopyButton.d.ts +19 -2
  38. package/dist/components/buttons/UCopyButton.js +57 -3
  39. package/dist/components/buttons/UCopyButton.styles.js +4 -4
  40. package/dist/components/buttons/UVoteButton.d.ts +14 -3
  41. package/dist/components/buttons/UVoteButton.js +62 -3
  42. package/dist/components/buttons/UVoteButton.styles.js +4 -4
  43. package/dist/components/{actions/UQuestionAction.component.d.ts → intents/UQuestionIntent.d.ts} +6 -2
  44. package/dist/components/intents/UQuestionIntent.js +41 -0
  45. package/dist/components/{actions/UQuestionAction.styles.js → intents/UQuestionIntent.styles.js} +4 -6
  46. package/dist/components/message/UMessage.d.ts +18 -2
  47. package/dist/components/message/UMessage.js +47 -2
  48. package/dist/components/message/UMessage.styles.js +4 -4
  49. package/dist/components/prompt/UPrompt.d.ts +32 -2
  50. package/dist/components/prompt/UPrompt.js +118 -2
  51. package/dist/components/prompt/UPrompt.styles.js +15 -5
  52. package/dist/components/references/URefCard.d.ts +30 -2
  53. package/dist/components/references/URefCard.js +97 -2
  54. package/dist/components/references/URefCard.styles.js +4 -4
  55. package/dist/components/references/URefCardGroup.d.ts +25 -2
  56. package/dist/components/references/URefCardGroup.js +69 -4
  57. package/dist/components/references/URefCardGroup.styles.js +4 -4
  58. package/dist/components/references/URefTag.d.ts +12 -2
  59. package/dist/components/references/URefTag.js +37 -2
  60. package/dist/components/references/URefTag.styles.js +4 -4
  61. package/dist/components/{widgets/UChartWidget.component.d.ts → views/UChartView.d.ts} +7 -4
  62. package/dist/components/views/UChartView.js +167 -0
  63. package/dist/components/{widgets/UChartWidget.styles.js → views/UChartView.styles.js} +4 -4
  64. package/dist/components/{widgets/UImagesWidget.component.d.ts → views/UImagesView.d.ts} +7 -4
  65. package/dist/components/views/UImagesView.js +144 -0
  66. package/dist/components/{widgets/UImagesWidget.styles.js → views/UImagesView.styles.js} +6 -5
  67. package/dist/components/{widgets/UMapWidget.component.d.ts → views/UMapView.d.ts} +7 -3
  68. package/dist/components/views/UMapView.js +45 -0
  69. package/dist/components/{widgets/UMapWidget.styles.js → views/UMapView.styles.js} +4 -4
  70. package/dist/components/{widgets/UVideoWidget.component.d.ts → views/UVideoView.d.ts} +7 -3
  71. package/dist/components/views/UVideoView.js +81 -0
  72. package/dist/components/{widgets/UVideoWidget.styles.js → views/UVideoView.styles.js} +4 -4
  73. package/dist/components/{widgets/UWidget.component.d.ts → views/UView.d.ts} +8 -5
  74. package/dist/components/views/UView.js +113 -0
  75. package/dist/components/{widgets/UWidget.styles.js → views/UView.styles.js} +4 -4
  76. package/dist/events/AttachEvent.d.ts +9 -0
  77. package/dist/events/ChoiceEvent.d.ts +9 -0
  78. package/dist/events/SendEvent.d.ts +7 -0
  79. package/dist/events/StopEvent.d.ts +7 -0
  80. package/dist/index.d.ts +13 -16
  81. package/dist/index.js +28 -56
  82. package/dist/react/UAttachButton.d.ts +11 -0
  83. package/dist/react/UAttachButton.js +12 -0
  84. package/dist/react/UChartView.d.ts +9 -0
  85. package/dist/react/UChartView.js +10 -0
  86. package/dist/react/UCodeBlock.d.ts +9 -0
  87. package/dist/react/UCodeBlock.js +10 -0
  88. package/dist/react/UCopyButton.d.ts +9 -0
  89. package/dist/react/UCopyButton.js +10 -0
  90. package/dist/react/UFileBlock.d.ts +11 -0
  91. package/dist/react/UFileBlock.js +12 -0
  92. package/dist/react/UImagesView.d.ts +9 -0
  93. package/dist/react/UImagesView.js +10 -0
  94. package/dist/react/UJsonBlock.d.ts +9 -0
  95. package/dist/react/UJsonBlock.js +10 -0
  96. package/dist/react/UMapView.d.ts +9 -0
  97. package/dist/react/UMapView.js +10 -0
  98. package/dist/react/UMarkedBlock.d.ts +9 -0
  99. package/dist/react/UMarkedBlock.js +10 -0
  100. package/dist/react/UMessage.d.ts +9 -0
  101. package/dist/react/UMessage.js +10 -0
  102. package/dist/react/UPrompt.d.ts +13 -0
  103. package/dist/react/UPrompt.js +13 -0
  104. package/dist/react/UQuestionIntent.d.ts +11 -0
  105. package/dist/react/UQuestionIntent.js +12 -0
  106. package/dist/react/URefBlock.d.ts +9 -0
  107. package/dist/react/URefBlock.js +10 -0
  108. package/dist/react/URefCard.d.ts +9 -0
  109. package/dist/react/URefCard.js +10 -0
  110. package/dist/react/URefCardGroup.d.ts +9 -0
  111. package/dist/react/URefCardGroup.js +10 -0
  112. package/dist/react/URefTag.d.ts +9 -0
  113. package/dist/react/URefTag.js +10 -0
  114. package/dist/react/UTableBlock.d.ts +9 -0
  115. package/dist/react/UTableBlock.js +10 -0
  116. package/dist/react/UTextBlock.d.ts +9 -0
  117. package/dist/react/UTextBlock.js +10 -0
  118. package/dist/react/UThinkBlock.d.ts +9 -0
  119. package/dist/react/UThinkBlock.js +10 -0
  120. package/dist/react/UToolBlock.d.ts +9 -0
  121. package/dist/react/UToolBlock.js +10 -0
  122. package/dist/react/UVideoView.d.ts +9 -0
  123. package/dist/react/UVideoView.js +10 -0
  124. package/dist/react/UView.d.ts +9 -0
  125. package/dist/react/UView.js +10 -0
  126. package/dist/react/UVoteButton.d.ts +9 -0
  127. package/dist/react/UVoteButton.js +10 -0
  128. package/dist/react/index.d.ts +23 -0
  129. package/dist/react/index.js +23 -0
  130. package/dist/types/BlockItem.d.ts +21 -32
  131. package/dist/types/Intents.d.ts +26 -0
  132. package/dist/types/Intents.js +30 -0
  133. package/dist/types/{Widgets.d.ts → Views.d.ts} +8 -8
  134. package/dist/types/Views.js +150 -0
  135. package/dist/utilities/IntentPromptBuilder.d.ts +40 -0
  136. package/dist/utilities/IntentPromptBuilder.js +95 -0
  137. package/dist/utilities/ViewPromptBuilder.d.ts +28 -0
  138. package/dist/utilities/ViewPromptBuilder.js +76 -0
  139. package/dist/utilities/dom-agent/DOMAgent.d.ts +74 -0
  140. package/dist/utilities/dom-agent/DOMController.d.ts +78 -0
  141. package/dist/utilities/dom-agent/DOMPromptBuilder.d.ts +54 -0
  142. package/dist/utilities/dom-agent/DOMScanner.d.ts +83 -0
  143. package/dist/utilities/dom-agent/index.d.ts +9 -0
  144. package/dist/utilities/dom-agent/types.d.ts +209 -0
  145. package/package.json +32 -16
  146. package/dist/assets/action-prompt.md.js +0 -3
  147. package/dist/assets/widget-prompt.md.js +0 -3
  148. package/dist/components/actions/UQuestionAction.component.js +0 -58
  149. package/dist/components/actions/UQuestionAction.d.ts +0 -7
  150. package/dist/components/actions/UQuestionAction.js +0 -5
  151. package/dist/components/blocks/UCodeBlock.component.d.ts +0 -25
  152. package/dist/components/blocks/UCodeBlock.component.js +0 -88
  153. package/dist/components/blocks/UFilesBlock.component.d.ts +0 -22
  154. package/dist/components/blocks/UFilesBlock.component.js +0 -192
  155. package/dist/components/blocks/UFilesBlock.d.ts +0 -7
  156. package/dist/components/blocks/UFilesBlock.js +0 -5
  157. package/dist/components/blocks/UJsonBlock.component.d.ts +0 -45
  158. package/dist/components/blocks/UJsonBlock.component.js +0 -140
  159. package/dist/components/blocks/UMarkedBlock.component.d.ts +0 -40
  160. package/dist/components/blocks/UMarkedBlock.component.js +0 -159
  161. package/dist/components/blocks/URefBlock.component.d.ts +0 -17
  162. package/dist/components/blocks/URefBlock.component.js +0 -73
  163. package/dist/components/blocks/UTableBlock.component.d.ts +0 -49
  164. package/dist/components/blocks/UTableBlock.component.js +0 -228
  165. package/dist/components/blocks/UTextBlock.component.d.ts +0 -37
  166. package/dist/components/blocks/UTextBlock.component.js +0 -123
  167. package/dist/components/blocks/UThinkBlock.component.d.ts +0 -23
  168. package/dist/components/blocks/UThinkBlock.component.js +0 -90
  169. package/dist/components/blocks/UToolBlock.component.d.ts +0 -20
  170. package/dist/components/blocks/UToolBlock.component.js +0 -80
  171. package/dist/components/buttons/UAttachButton.component.d.ts +0 -22
  172. package/dist/components/buttons/UAttachButton.component.js +0 -89
  173. package/dist/components/buttons/UCopyButton.component.d.ts +0 -20
  174. package/dist/components/buttons/UCopyButton.component.js +0 -81
  175. package/dist/components/buttons/UReportButton.component.d.ts +0 -9
  176. package/dist/components/buttons/UReportButton.component.js +0 -36
  177. package/dist/components/buttons/UReportButton.d.ts +0 -7
  178. package/dist/components/buttons/UReportButton.js +0 -5
  179. package/dist/components/buttons/UReportButton.styles.js +0 -14
  180. package/dist/components/buttons/URetryButton.component.d.ts +0 -11
  181. package/dist/components/buttons/URetryButton.component.js +0 -53
  182. package/dist/components/buttons/URetryButton.d.ts +0 -7
  183. package/dist/components/buttons/URetryButton.js +0 -5
  184. package/dist/components/buttons/URetryButton.styles.js +0 -26
  185. package/dist/components/buttons/UShareButton.component.d.ts +0 -9
  186. package/dist/components/buttons/UShareButton.component.js +0 -36
  187. package/dist/components/buttons/UShareButton.d.ts +0 -7
  188. package/dist/components/buttons/UShareButton.js +0 -5
  189. package/dist/components/buttons/UShareButton.styles.js +0 -14
  190. package/dist/components/buttons/UVoteButton.component.d.ts +0 -15
  191. package/dist/components/buttons/UVoteButton.component.js +0 -73
  192. package/dist/components/message/UMessage.component.d.ts +0 -19
  193. package/dist/components/message/UMessage.component.js +0 -56
  194. package/dist/components/prompt/UPrompt.component.d.ts +0 -25
  195. package/dist/components/prompt/UPrompt.component.js +0 -113
  196. package/dist/components/references/URefCard.component.d.ts +0 -27
  197. package/dist/components/references/URefCard.component.js +0 -109
  198. package/dist/components/references/URefCardGroup.component.d.ts +0 -26
  199. package/dist/components/references/URefCardGroup.component.js +0 -88
  200. package/dist/components/references/URefTag.component.d.ts +0 -13
  201. package/dist/components/references/URefTag.component.js +0 -54
  202. package/dist/components/widgets/UChartWidget.component.js +0 -180
  203. package/dist/components/widgets/UChartWidget.d.ts +0 -7
  204. package/dist/components/widgets/UChartWidget.js +0 -5
  205. package/dist/components/widgets/UImagesWidget.component.js +0 -164
  206. package/dist/components/widgets/UImagesWidget.d.ts +0 -7
  207. package/dist/components/widgets/UImagesWidget.js +0 -5
  208. package/dist/components/widgets/UMapWidget.component.js +0 -65
  209. package/dist/components/widgets/UMapWidget.d.ts +0 -7
  210. package/dist/components/widgets/UMapWidget.js +0 -5
  211. package/dist/components/widgets/UMapWidget.styles.d.ts +0 -1
  212. package/dist/components/widgets/UVideoWidget.component.js +0 -106
  213. package/dist/components/widgets/UVideoWidget.d.ts +0 -7
  214. package/dist/components/widgets/UVideoWidget.js +0 -5
  215. package/dist/components/widgets/UVideoWidget.styles.d.ts +0 -1
  216. package/dist/components/widgets/UWidget.component.js +0 -140
  217. package/dist/components/widgets/UWidget.d.ts +0 -7
  218. package/dist/components/widgets/UWidget.js +0 -5
  219. package/dist/components/widgets/UWidget.styles.d.ts +0 -1
  220. package/dist/events/UCancelEvent.d.ts +0 -6
  221. package/dist/events/USubmitEvent.d.ts +0 -6
  222. package/dist/types/Actions.d.ts +0 -24
  223. package/dist/types/Actions.js +0 -34
  224. package/dist/types/Widgets.js +0 -115
  225. package/dist/utilities/ActionPromptBuilder.d.ts +0 -40
  226. package/dist/utilities/ActionPromptBuilder.js +0 -93
  227. package/dist/utilities/WidgetPromptBuilder.d.ts +0 -28
  228. package/dist/utilities/WidgetPromptBuilder.js +0 -87
  229. package/dist/utilities/converters.d.ts +0 -9
  230. package/dist/utilities/converters.js +0 -19
  231. /package/dist/components/{actions/UQuestionAction.styles.d.ts → blocks/UFileBlock.styles.d.ts} +0 -0
  232. /package/dist/components/{blocks/UFilesBlock.styles.d.ts → intents/UQuestionIntent.styles.d.ts} +0 -0
  233. /package/dist/components/{buttons/UReportButton.styles.d.ts → views/UChartView.styles.d.ts} +0 -0
  234. /package/dist/components/{buttons/URetryButton.styles.d.ts → views/UImagesView.styles.d.ts} +0 -0
  235. /package/dist/components/{buttons/UShareButton.styles.d.ts → views/UMapView.styles.d.ts} +0 -0
  236. /package/dist/components/{widgets/UChartWidget.styles.d.ts → views/UVideoView.styles.d.ts} +0 -0
  237. /package/dist/components/{widgets/UImagesWidget.styles.d.ts → views/UView.styles.d.ts} +0 -0
@@ -0,0 +1,154 @@
1
+ import { __decorateMetadata } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/decorateMetadata.js";
2
+ import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/decorate.js";
3
+ import { styles } from "./UFileBlock.styles.js";
4
+ import { html } from "lit";
5
+ import { customElement, property } from "lit/decorators.js";
6
+ import "@iyulab/components/dist/components/icon/UIcon.js";
7
+ import "@iyulab/components/dist/components/spinner/USpinner.js";
8
+ import "@iyulab/components/dist/components/button/UButton.js";
9
+ import { UElement } from "@iyulab/components/dist/components/UElement.js";
10
+ //#region src/components/blocks/UFileBlock.ts
11
+ var UFileBlock = class UFileBlock extends UElement {
12
+ constructor(..._args) {
13
+ super(..._args);
14
+ this.removable = false;
15
+ this.handleDownloadClick = (e) => {
16
+ e.stopPropagation();
17
+ if (!this.url) return;
18
+ const a = document.createElement("a");
19
+ a.href = this.url;
20
+ a.download = this.name || "unknown-file";
21
+ a.target = "_blank";
22
+ a.rel = "noopener noreferrer";
23
+ document.body.appendChild(a);
24
+ a.click();
25
+ a.remove();
26
+ };
27
+ this.handleRemoveClick = (e) => {
28
+ e.stopPropagation();
29
+ if (this.fire("remove")) this.remove();
30
+ };
31
+ }
32
+ static {
33
+ this.styles = [super.styles, styles];
34
+ }
35
+ render() {
36
+ return html`
37
+ <div class="thumbnail">
38
+ <u-spinner
39
+ ?hidden=${this.status !== "uploading"}
40
+ ></u-spinner>
41
+ <u-icon
42
+ ?hidden=${this.status !== "error"}
43
+ lib="bootstrap"
44
+ name="file-earmark-x"
45
+ ></u-icon>
46
+ <u-icon
47
+ ?hidden=${this.status && this.status !== "idle"}
48
+ lib="bootstrap"
49
+ name=${this.resolveIcon(this.type)}
50
+ ></u-icon>
51
+ <u-button class="download-btn"
52
+ ?hidden=${!this.url || this.status === "uploading" || this.status === "error"}
53
+ title="Download"
54
+ @click=${this.handleDownloadClick}>
55
+ <u-icon lib="bootstrap" name="download"></u-icon>
56
+ </u-button>
57
+ </div>
58
+
59
+ <div class="info">
60
+ <div class="name">${this.name}</div>
61
+ <div class="meta">
62
+ <span class="type">
63
+ ${this.resolveExt(this.name, this.type)}
64
+ </span>
65
+ <span class="size">
66
+ ${this.formatSize(this.size || 0)}
67
+ </span>
68
+ </div>
69
+ </div>
70
+
71
+ <u-button class="remove-btn"
72
+ ?hidden=${!this.removable}
73
+ title="Remove"
74
+ @click=${this.handleRemoveClick}>
75
+ <u-icon lib="internal" name="x-lg"></u-icon>
76
+ </u-button>
77
+ `;
78
+ }
79
+ /** MIME 타입 → Bootstrap Icon 이름 */
80
+ resolveIcon(mimeType) {
81
+ if (!mimeType) return "file-earmark";
82
+ if (mimeType.startsWith("image/")) return "file-earmark-image";
83
+ if (mimeType.startsWith("video/")) return "file-earmark-play";
84
+ if (mimeType.startsWith("audio/")) return "file-earmark-music";
85
+ if (mimeType === "application/pdf") return "file-earmark-pdf";
86
+ if ([
87
+ "application/json",
88
+ "application/javascript",
89
+ "application/typescript",
90
+ "application/xml",
91
+ "text/html",
92
+ "text/css",
93
+ "text/javascript",
94
+ "text/x-python",
95
+ "text/x-java-source"
96
+ ].includes(mimeType) || mimeType.startsWith("text/x-")) return "file-earmark-code";
97
+ if ([
98
+ "application/vnd.ms-excel",
99
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
100
+ "text/csv"
101
+ ].includes(mimeType)) return "file-earmark-spreadsheet";
102
+ if ([
103
+ "application/zip",
104
+ "application/x-zip-compressed",
105
+ "application/x-tar",
106
+ "application/x-rar-compressed",
107
+ "application/gzip",
108
+ "application/x-7z-compressed"
109
+ ].includes(mimeType)) return "file-earmark-zip";
110
+ if (mimeType.startsWith("text/")) return "file-earmark-text";
111
+ return "file-earmark";
112
+ }
113
+ /** 파일명 또는 MIME 타입에서 확장자를 추출합니다. */
114
+ resolveExt(name, mimeType) {
115
+ if (name) {
116
+ const dot = name.lastIndexOf(".");
117
+ if (dot !== -1 && dot < name.length - 1) return name.slice(dot + 1).toLowerCase();
118
+ }
119
+ return mimeType ? {
120
+ "image/jpeg": "jpg",
121
+ "image/png": "png",
122
+ "image/gif": "gif",
123
+ "image/webp": "webp",
124
+ "image/svg+xml": "svg",
125
+ "application/pdf": "pdf",
126
+ "text/plain": "txt",
127
+ "text/csv": "csv",
128
+ "application/json": "json",
129
+ "application/zip": "zip"
130
+ }[mimeType] ?? mimeType.split("/").pop() ?? "" : "";
131
+ }
132
+ /** bytes → 읽기 좋은 크기 문자열 */
133
+ formatSize(bytes) {
134
+ if (bytes < 1024) return `${bytes} B`;
135
+ if (bytes < 1024 ** 2) return `${(bytes / 1024).toFixed(1)} KB`;
136
+ if (bytes < 1024 ** 3) return `${(bytes / 1024 ** 2).toFixed(1)} MB`;
137
+ return `${(bytes / 1024 ** 3).toFixed(2)} GB`;
138
+ }
139
+ };
140
+ __decorate([property({
141
+ type: Boolean,
142
+ reflect: true
143
+ }), __decorateMetadata("design:type", Object)], UFileBlock.prototype, "removable", void 0);
144
+ __decorate([property({
145
+ type: String,
146
+ reflect: true
147
+ }), __decorateMetadata("design:type", String)], UFileBlock.prototype, "status", void 0);
148
+ __decorate([property({ type: String }), __decorateMetadata("design:type", String)], UFileBlock.prototype, "name", void 0);
149
+ __decorate([property({ type: String }), __decorateMetadata("design:type", String)], UFileBlock.prototype, "type", void 0);
150
+ __decorate([property({ type: Number }), __decorateMetadata("design:type", Number)], UFileBlock.prototype, "size", void 0);
151
+ __decorate([property({ type: String }), __decorateMetadata("design:type", String)], UFileBlock.prototype, "url", void 0);
152
+ UFileBlock = __decorate([customElement("u-file-block")], UFileBlock);
153
+ //#endregion
154
+ export { UFileBlock };
@@ -1,20 +1,13 @@
1
- import { css } from 'lit';
2
-
3
- const styles = css`
1
+ import { css } from "lit";
2
+ //#region src/components/blocks/UFileBlock.styles.ts
3
+ var styles = css`
4
4
  :host {
5
- display: grid;
6
- grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
7
- gap: 6px;
8
- font-size: 14px;
9
- width: 100%;
10
- }
11
-
12
- .item {
13
5
  position: relative;
14
6
  display: flex;
15
7
  flex-direction: row;
16
8
  align-items: center;
17
9
  min-width: 0;
10
+ max-width: 200px;
18
11
  gap: 10px;
19
12
  padding: 8px 10px;
20
13
  border: 1px solid var(--u-border-color);
@@ -23,40 +16,16 @@ const styles = css`
23
16
  overflow: visible;
24
17
  cursor: pointer;
25
18
  transition: background-color 0.12s ease, border-color 0.12s ease;
19
+ font-size: 14px;
26
20
  }
27
- .item:hover {
21
+ :host(:hover) {
28
22
  background-color: var(--u-neutral-100);
29
23
  border-color: var(--u-border-color-strong);
30
24
  }
31
25
 
32
- /* uploading */
33
- .item[phase="uploading"] {
34
- border-color: var(--u-blue-400);
35
- background-color: var(--u-blue-0);
36
- cursor: default;
37
- }
38
- .item[phase="uploading"] .thumbnail {
39
- background-color: var(--u-blue-100);
40
- color: var(--u-blue-600);
41
- }
42
- .item[phase="uploading"]:hover {
43
- background-color: var(--u-blue-0);
44
- border-color: var(--u-blue-400);
45
- }
46
-
47
- /* error */
48
- .item[phase="error"] {
49
- border-color: var(--u-red-400);
50
- background-color: var(--u-red-0);
51
- }
52
- .item[phase="error"] .thumbnail {
53
- background-color: var(--u-red-100);
26
+ u-icon[name="file-earmark-x"] {
54
27
  color: var(--u-red-600);
55
28
  }
56
- .item[phase="error"]:hover {
57
- background-color: var(--u-red-0);
58
- border-color: var(--u-red-500);
59
- }
60
29
 
61
30
  .thumbnail {
62
31
  position: relative;
@@ -70,20 +39,8 @@ const styles = css`
70
39
  font-size: 16px;
71
40
  border-radius: 6px;
72
41
  background-color: var(--u-neutral-200);
73
- }
74
-
75
- .thumbnail-overlay {
76
- position: absolute;
77
- inset: 0;
78
- display: flex;
79
- align-items: center;
80
- justify-content: center;
81
- border-radius: 6px;
82
- font-size: 14px;
83
- background-color: color-mix(in srgb, currentColor 15%, transparent);
84
- }
85
- .item[phase="uploading"] .thumbnail-overlay {
86
- animation: pulse 1.4s ease-in-out infinite;
42
+ transition: background 0.15s ease;
43
+ overflow: hidden;
87
44
  }
88
45
 
89
46
  .info {
@@ -125,33 +82,6 @@ const styles = css`
125
82
  font-variant-numeric: tabular-nums;
126
83
  }
127
84
 
128
- .error-msg {
129
- display: flex;
130
- align-items: center;
131
- gap: 3px;
132
- color: var(--u-red-600);
133
- font-size: 10px;
134
- font-weight: 500;
135
- white-space: nowrap;
136
- overflow: hidden;
137
- text-overflow: ellipsis;
138
- }
139
-
140
- .upload-progress {
141
- position: absolute;
142
- bottom: 0;
143
- left: 0;
144
- right: 0;
145
- height: 3px;
146
- border-radius: 0 0 8px 8px;
147
- border: none;
148
- overflow: hidden;
149
- }
150
- .upload-progress::part(indicator) {
151
- background-color: var(--u-blue-500);
152
- border-radius: 0 0 8px 8px;
153
- }
154
-
155
85
  .download-btn {
156
86
  position: absolute;
157
87
  inset: 0;
@@ -165,7 +95,7 @@ const styles = css`
165
95
  pointer-events: none;
166
96
  transition: opacity 0.15s ease;
167
97
  }
168
- .item:hover .download-btn {
98
+ .thumbnail:hover .download-btn {
169
99
  opacity: 1;
170
100
  pointer-events: auto;
171
101
  }
@@ -186,21 +116,13 @@ const styles = css`
186
116
  pointer-events: none;
187
117
  transition: opacity 0.12s ease, background-color 0.12s ease;
188
118
  }
189
- .item:hover .remove-btn {
119
+ :host(:hover) .remove-btn {
190
120
  opacity: 1;
191
121
  pointer-events: auto;
192
122
  }
193
123
  .remove-btn:hover {
194
124
  background-color: var(--u-red-600);
195
125
  }
196
- .remove-btn:active {
197
- background-color: var(--u-red-700);
198
- }
199
-
200
- @keyframes pulse {
201
- 0%, 100% { opacity: 1; }
202
- 50% { opacity: 0.4; }
203
- }
204
126
  `;
205
-
127
+ //#endregion
206
128
  export { styles };
@@ -1,7 +1,49 @@
1
- import { UJsonBlock } from './UJsonBlock.component.js';
1
+ import { PropertyValues, TemplateResult } from 'lit';
2
+ import { UElement } from '@iyulab/components/dist/components/UElement.js';
3
+ import { JsonNode } from '../../types/JsonNode.js';
4
+ /**
5
+ * json 데이터를 트리 형태로 시각화하는 컴포넌트입니다.
6
+ */
7
+ export declare class UJsonBlock extends UElement {
8
+ static styles: import('lit').CSSResultGroup[];
9
+ /** 초기 확장 상태를 관리하는 속성입니다. */
10
+ expanded: boolean;
11
+ /** JSON 데이터 (속성으로 전달 가능) */
12
+ value: JsonNode;
13
+ state: Record<string, boolean>;
14
+ connectedCallback(): void;
15
+ protected willUpdate(changedProperties: PropertyValues): void;
16
+ render(): TemplateResult<1>;
17
+ /**
18
+ * JsonNode를 렌더링합니다.
19
+ * @param value - JsonNode (JsonObject, JsonArray, 또는 JsonValue)
20
+ * @param parent - 부모 노드의 경로
21
+ */
22
+ private renderNode;
23
+ /**
24
+ * JsonValue를 렌더링합니다.
25
+ * @param node - JsonValue (string, number, boolean, null 등)
26
+ */
27
+ private renderValue;
28
+ /**
29
+ * JsonObject 또는 JsonArray를 렌더링합니다.
30
+ * @param node - JsonObject 또는 JsonArray
31
+ * @param depth - 현재 깊이
32
+ */
33
+ private renderObject;
34
+ /**
35
+ * 노드의 미리보기를 렌더링합니다.
36
+ * @param node - JsonObject 또는 JsonArray
37
+ */
38
+ private renderPreview;
39
+ /** JSON 데이터를 순회하며 각 경로의 확장 상태를 설정합니다. */
40
+ private setState;
41
+ private isValueType;
42
+ /** 노드 확장/축소 클릭 핸들러 */
43
+ private handlePropertyKeyClick;
44
+ }
2
45
  declare global {
3
46
  interface HTMLElementTagNameMap {
4
47
  'u-json-block': UJsonBlock;
5
48
  }
6
49
  }
7
- export { UJsonBlock };
@@ -1,5 +1,130 @@
1
- import { UJsonBlock } from './UJsonBlock.component.js';
2
-
3
- UJsonBlock.define("u-json-block");
1
+ import { __decorateMetadata } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/decorateMetadata.js";
2
+ import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/decorate.js";
3
+ import { styles } from "./UJsonBlock.styles.js";
4
+ import { html } from "lit";
5
+ import { customElement, property, state } from "lit/decorators.js";
6
+ import { UElement } from "@iyulab/components/dist/components/UElement.js";
7
+ import { map } from "lit/directives/map.js";
8
+ import { when } from "lit/directives/when.js";
9
+ import { jsonAttrConverter } from "@iyulab/components/dist/utilities/converters.js";
10
+ //#region src/components/blocks/UJsonBlock.ts
11
+ var _ref;
12
+ var UJsonBlock = class UJsonBlock extends UElement {
13
+ constructor(..._args) {
14
+ super(..._args);
15
+ this.expanded = true;
16
+ this.value = {};
17
+ this.state = {};
18
+ this.isValueType = (value) => {
19
+ return value !== Object(value);
20
+ };
21
+ }
22
+ static {
23
+ this.styles = [super.styles, styles];
24
+ }
25
+ connectedCallback() {
26
+ super.connectedCallback();
27
+ this.setAttribute("tabindex", "0");
28
+ }
29
+ willUpdate(changedProperties) {
30
+ super.willUpdate(changedProperties);
31
+ if (changedProperties.has("value") || changedProperties.has("expanded")) this.state = this.setState(this.value);
32
+ }
33
+ render() {
34
+ return html`
35
+ <div part="base">
36
+ ${this.renderNode(this.value)}
37
+ </div>
38
+ `;
39
+ }
40
+ /**
41
+ * JsonNode를 렌더링합니다.
42
+ * @param value - JsonNode (JsonObject, JsonArray, 또는 JsonValue)
43
+ * @param parent - 부모 노드의 경로
44
+ */
45
+ renderNode(value, parent = "") {
46
+ return this.isValueType(value) ? this.renderValue(value) : this.renderObject(value, parent);
47
+ }
48
+ /**
49
+ * JsonValue를 렌더링합니다.
50
+ * @param node - JsonValue (string, number, boolean, null 등)
51
+ */
52
+ renderValue(node) {
53
+ const type = node === null ? "null" : Array.isArray(node) ? "array" : typeof node === "object" ? "object" : typeof node;
54
+ return html`
55
+ <span part="${type}" class="${type}" role="treeitem">
56
+ ${JSON.stringify(node)}
57
+ </span>
58
+ `;
59
+ }
60
+ /**
61
+ * JsonObject 또는 JsonArray를 렌더링합니다.
62
+ * @param node - JsonObject 또는 JsonArray
63
+ * @param depth - 현재 깊이
64
+ */
65
+ renderObject(node, parent) {
66
+ return html`
67
+ <ul part="object" role="group">
68
+ ${map(Object.entries(node), ([key, value]) => {
69
+ const path = parent ? `${parent}.${key}` : key;
70
+ const isValue = this.isValueType(value);
71
+ const isExpanded = this.state[path] ?? this.expanded;
72
+ return html`
73
+ <li part="property" role="treeitem"
74
+ data-path="${path}"
75
+ aria-expanded="${isExpanded ? "true" : "false"}">
76
+ <span part="key"
77
+ class="key"
78
+ ?collapsable="${!isValue}"
79
+ ?collapsed="${!isValue && !isExpanded}"
80
+ @click=${!isValue ? () => this.handlePropertyKeyClick(path) : null}>
81
+ ${key}:
82
+ ${when(!isValue && !isExpanded, () => this.renderPreview(value))}
83
+ </span>
4
84
 
85
+ ${when(isValue || isExpanded, () => this.renderNode(value, path))}
86
+ </li>`;
87
+ })}
88
+ </ul>
89
+ `;
90
+ }
91
+ /**
92
+ * 노드의 미리보기를 렌더링합니다.
93
+ * @param node - JsonObject 또는 JsonArray
94
+ */
95
+ renderPreview(node) {
96
+ return html`
97
+ <span part="preview" class="preview">
98
+ ${Array.isArray(node) ? node.length === 0 ? "[ ]" : `[ ${node.length} items ]` : Object.keys(node).length === 0 ? "{ }" : `{ ${Object.keys(node).length} properties }`}
99
+ </span>
100
+ `;
101
+ }
102
+ /** JSON 데이터를 순회하며 각 경로의 확장 상태를 설정합니다. */
103
+ setState(value, parent = "") {
104
+ if (typeof value !== "object" || value === null) return {};
105
+ const state = {};
106
+ Object.entries(value).forEach(([key, item]) => {
107
+ const path = parent ? `${parent}.${key}` : key;
108
+ state[path] = this.expanded;
109
+ Object.assign(state, this.setState(item, path));
110
+ });
111
+ return state;
112
+ }
113
+ /** 노드 확장/축소 클릭 핸들러 */
114
+ handlePropertyKeyClick(path) {
115
+ const isExpanded = this.state[path] ?? false;
116
+ this.state = {
117
+ ...this.state,
118
+ [path]: !isExpanded
119
+ };
120
+ }
121
+ };
122
+ __decorate([property({ type: Boolean }), __decorateMetadata("design:type", Boolean)], UJsonBlock.prototype, "expanded", void 0);
123
+ __decorate([property({
124
+ type: Object,
125
+ converter: jsonAttrConverter()
126
+ }), __decorateMetadata("design:type", Object)], UJsonBlock.prototype, "value", void 0);
127
+ __decorate([state(), __decorateMetadata("design:type", typeof (_ref = typeof Record !== "undefined" && Record) === "function" ? _ref : Object)], UJsonBlock.prototype, "state", void 0);
128
+ UJsonBlock = __decorate([customElement("u-json-block")], UJsonBlock);
129
+ //#endregion
5
130
  export { UJsonBlock };
@@ -1,6 +1,6 @@
1
- import { css } from 'lit';
2
-
3
- const styles = css`
1
+ import { css } from "lit";
2
+ //#region src/components/blocks/UJsonBlock.styles.ts
3
+ var styles = css`
4
4
  :host {
5
5
  --indent-size: 2em;
6
6
 
@@ -111,5 +111,5 @@ const styles = css`
111
111
  bottom: 0.2em;
112
112
  }
113
113
  `;
114
-
114
+ //#endregion
115
115
  export { styles };
@@ -1,7 +1,49 @@
1
- import { UMarkedBlock } from './UMarkedBlock.component.js';
1
+ import { PropertyValues } from 'lit';
2
+ import { UElement } from '@iyulab/components/dist/components/UElement.js';
3
+ import { ReferenceCitation } from '../../types/References.js';
4
+ /**
5
+ * 마크다운 컨텐츠를 렌더링하는 컴포넌트입니다.
6
+ *
7
+ * 주의:
8
+ * - refs로 삽입되는 커스텀 태그(u-ref-*)는 속성/내용을 모두 escape하여 XSS를 방지합니다.
9
+ * - 코드블록 내부는 HTML을 전부 텍스트로 취급(escape)하며, refs 태그는 통째 제거합니다.
10
+ * - 인덱스 기반 삽입(ref.endIndex)이 깨지지 않도록 "normalize(제로폭 제거)"를 insertRefs 전에 1회 수행합니다.
11
+ */
12
+ export declare class UMarkedBlock extends UElement {
13
+ static styles: import('lit').CSSResultGroup[];
14
+ /** 마크다운 컨텐츠를 렌더링할 때 사용할 값입니다. */
15
+ value?: string;
16
+ /** 컨텐츠의 인용 출처들입니다. */
17
+ refs?: ReferenceCitation[];
18
+ private parser;
19
+ private placeholder;
20
+ private queued;
21
+ private timer?;
22
+ disconnectedCallback(): void;
23
+ protected shouldUpdate(_changedProperties: PropertyValues): boolean;
24
+ protected willUpdate(changedProperties: PropertyValues): void;
25
+ render(): import('lit-html/directive.js').DirectiveResult<typeof import('lit-html/directives/unsafe-html.js').UnsafeHTMLDirective>;
26
+ /**
27
+ * 코드블록은 별도의 컴포넌트로 렌더링 합니다.
28
+ */
29
+ private renderCode;
30
+ /**
31
+ * 테이블은 JSON 데이터로 변환하여 별도의 컴포넌트로 렌더링합니다.
32
+ * 셀 내부의 인라인 마크다운(볼드, 코드, br 등)도 HTML로 변환합니다.
33
+ */
34
+ private renderTable;
35
+ /**
36
+ * 인용/출처 참조객체가 있을때 ref 태그 HTML을 this.placeholder에 보관하고
37
+ * 마크다운 문자열의 해당 위치에 주석 플레이스홀더를 삽입합니다.
38
+ */
39
+ private insertRefs;
40
+ /**
41
+ * 코드블록 내부의 <!--ref:idx--> 플레이스홀더와 그 외 refs 태그를 모두 제거하여 HTML이 코드로 렌더링되도록 합니다.
42
+ */
43
+ private removeRefs;
44
+ }
2
45
  declare global {
3
46
  interface HTMLElementTagNameMap {
4
47
  "u-marked-block": UMarkedBlock;
5
48
  }
6
49
  }
7
- export { UMarkedBlock };