@kispace-io/core 0.7.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 (272) hide show
  1. package/dist/api/base-classes.d.ts +7 -0
  2. package/dist/api/base-classes.d.ts.map +1 -0
  3. package/dist/api/constants.d.ts +2 -0
  4. package/dist/api/constants.d.ts.map +1 -0
  5. package/dist/api/index.d.ts +6 -0
  6. package/dist/api/index.d.ts.map +1 -0
  7. package/dist/api/index.js +80 -0
  8. package/dist/api/index.js.map +1 -0
  9. package/dist/api/services.d.ts +27 -0
  10. package/dist/api/services.d.ts.map +1 -0
  11. package/dist/api/types.d.ts +11 -0
  12. package/dist/api/types.d.ts.map +1 -0
  13. package/dist/commands/files.d.ts +2 -0
  14. package/dist/commands/files.d.ts.map +1 -0
  15. package/dist/commands/global.d.ts +1 -0
  16. package/dist/commands/global.d.ts.map +1 -0
  17. package/dist/commands/index.d.ts +1 -0
  18. package/dist/commands/index.d.ts.map +1 -0
  19. package/dist/commands/version-info.d.ts +2 -0
  20. package/dist/commands/version-info.d.ts.map +1 -0
  21. package/dist/components/index.d.ts +1 -0
  22. package/dist/components/index.d.ts.map +1 -0
  23. package/dist/components/k-app-selector.d.ts +17 -0
  24. package/dist/components/k-app-selector.d.ts.map +1 -0
  25. package/dist/components/k-app-switcher.d.ts +13 -0
  26. package/dist/components/k-app-switcher.d.ts.map +1 -0
  27. package/dist/components/k-command.d.ts +31 -0
  28. package/dist/components/k-command.d.ts.map +1 -0
  29. package/dist/components/k-extensions.d.ts +32 -0
  30. package/dist/components/k-extensions.d.ts.map +1 -0
  31. package/dist/components/k-fastviews.d.ts +34 -0
  32. package/dist/components/k-fastviews.d.ts.map +1 -0
  33. package/dist/components/k-filebrowser.d.ts +40 -0
  34. package/dist/components/k-filebrowser.d.ts.map +1 -0
  35. package/dist/components/k-language-selector.d.ts +12 -0
  36. package/dist/components/k-language-selector.d.ts.map +1 -0
  37. package/dist/components/k-log-terminal.d.ts +36 -0
  38. package/dist/components/k-log-terminal.d.ts.map +1 -0
  39. package/dist/components/k-part-name.d.ts +12 -0
  40. package/dist/components/k-part-name.d.ts.map +1 -0
  41. package/dist/components/k-tasks.d.ts +13 -0
  42. package/dist/components/k-tasks.d.ts.map +1 -0
  43. package/dist/components/k-workspace-name.d.ts +14 -0
  44. package/dist/components/k-workspace-name.d.ts.map +1 -0
  45. package/dist/contributions/default-ui-contributions.d.ts +2 -0
  46. package/dist/contributions/default-ui-contributions.d.ts.map +1 -0
  47. package/dist/contributions/index.d.ts +1 -0
  48. package/dist/contributions/index.d.ts.map +1 -0
  49. package/dist/contributions/marketplace-catalog-contributions.d.ts +2 -0
  50. package/dist/contributions/marketplace-catalog-contributions.d.ts.map +1 -0
  51. package/dist/core/app-host-config.d.ts +7 -0
  52. package/dist/core/app-host-config.d.ts.map +1 -0
  53. package/dist/core/apploader.d.ts +214 -0
  54. package/dist/core/apploader.d.ts.map +1 -0
  55. package/dist/core/appstate.d.ts +12 -0
  56. package/dist/core/appstate.d.ts.map +1 -0
  57. package/dist/core/commandregistry.d.ts +79 -0
  58. package/dist/core/commandregistry.d.ts.map +1 -0
  59. package/dist/core/config.d.ts +15 -0
  60. package/dist/core/config.d.ts.map +1 -0
  61. package/dist/core/constants.d.ts +21 -0
  62. package/dist/core/constants.d.ts.map +1 -0
  63. package/dist/core/contributionregistry.d.ts +49 -0
  64. package/dist/core/contributionregistry.d.ts.map +1 -0
  65. package/dist/core/di.d.ts +18 -0
  66. package/dist/core/di.d.ts.map +1 -0
  67. package/dist/core/dialogservice.d.ts +33 -0
  68. package/dist/core/dialogservice.d.ts.map +1 -0
  69. package/dist/core/editorregistry.d.ts +73 -0
  70. package/dist/core/editorregistry.d.ts.map +1 -0
  71. package/dist/core/esmsh-service.d.ts +40 -0
  72. package/dist/core/esmsh-service.d.ts.map +1 -0
  73. package/dist/core/events.d.ts +7 -0
  74. package/dist/core/events.d.ts.map +1 -0
  75. package/dist/core/events.js +63 -0
  76. package/dist/core/events.js.map +1 -0
  77. package/dist/core/extensionregistry.d.ts +98 -0
  78. package/dist/core/extensionregistry.d.ts.map +1 -0
  79. package/dist/core/filesys.d.ts +139 -0
  80. package/dist/core/filesys.d.ts.map +1 -0
  81. package/dist/core/i18n.d.ts +50 -0
  82. package/dist/core/i18n.d.ts.map +1 -0
  83. package/dist/core/index.d.ts +1 -0
  84. package/dist/core/index.d.ts.map +1 -0
  85. package/dist/core/k-utils.d.ts +2 -0
  86. package/dist/core/k-utils.d.ts.map +1 -0
  87. package/dist/core/keybindings.d.ts +67 -0
  88. package/dist/core/keybindings.d.ts.map +1 -0
  89. package/dist/core/logger.d.ts +44 -0
  90. package/dist/core/logger.d.ts.map +1 -0
  91. package/dist/core/marketplaceregistry.d.ts +25 -0
  92. package/dist/core/marketplaceregistry.d.ts.map +1 -0
  93. package/dist/core/packageinfoservice.d.ts +16 -0
  94. package/dist/core/packageinfoservice.d.ts.map +1 -0
  95. package/dist/core/persistenceservice.d.ts +6 -0
  96. package/dist/core/persistenceservice.d.ts.map +1 -0
  97. package/dist/core/settingsservice.d.ts +19 -0
  98. package/dist/core/settingsservice.d.ts.map +1 -0
  99. package/dist/core/signals.d.ts +3 -0
  100. package/dist/core/signals.d.ts.map +1 -0
  101. package/dist/core/taskservice.d.ts +20 -0
  102. package/dist/core/taskservice.d.ts.map +1 -0
  103. package/dist/core/toast.d.ts +4 -0
  104. package/dist/core/toast.d.ts.map +1 -0
  105. package/dist/core/tree-utils.d.ts +16 -0
  106. package/dist/core/tree-utils.d.ts.map +1 -0
  107. package/dist/dialogs/confirm-dialog.d.ts +14 -0
  108. package/dist/dialogs/confirm-dialog.d.ts.map +1 -0
  109. package/dist/dialogs/index.d.ts +5 -0
  110. package/dist/dialogs/index.d.ts.map +1 -0
  111. package/dist/dialogs/info-dialog.d.ts +13 -0
  112. package/dist/dialogs/info-dialog.d.ts.map +1 -0
  113. package/dist/dialogs/navigable-info-dialog.d.ts +33 -0
  114. package/dist/dialogs/navigable-info-dialog.d.ts.map +1 -0
  115. package/dist/dialogs/prompt-dialog.d.ts +21 -0
  116. package/dist/dialogs/prompt-dialog.d.ts.map +1 -0
  117. package/dist/externals/lit.d.ts +20 -0
  118. package/dist/externals/lit.d.ts.map +1 -0
  119. package/dist/externals/lit.js +15 -0
  120. package/dist/externals/lit.js.map +1 -0
  121. package/dist/externals/third-party.d.ts +7 -0
  122. package/dist/externals/third-party.d.ts.map +1 -0
  123. package/dist/externals/third-party.js +2 -0
  124. package/dist/externals/third-party.js.map +1 -0
  125. package/dist/externals/webawesome.d.ts +1 -0
  126. package/dist/externals/webawesome.d.ts.map +1 -0
  127. package/dist/externals/webawesome.js +52 -0
  128. package/dist/externals/webawesome.js.map +1 -0
  129. package/dist/i18n/extensions.json.d.ts +42 -0
  130. package/dist/i18n/fastviews.json.d.ts +13 -0
  131. package/dist/i18n/filebrowser.json.d.ts +35 -0
  132. package/dist/i18n/index.d.ts +2 -0
  133. package/dist/i18n/index.d.ts.map +1 -0
  134. package/dist/i18n/logterminal.json.d.ts +45 -0
  135. package/dist/i18n/partname.json.d.ts +15 -0
  136. package/dist/i18n/tasks.json.d.ts +15 -0
  137. package/dist/i18n/workspace.json.d.ts +15 -0
  138. package/dist/index.d.ts +2 -0
  139. package/dist/index.d.ts.map +1 -0
  140. package/dist/index.js +80 -0
  141. package/dist/index.js.map +1 -0
  142. package/dist/k-icon-BZC7dQV0.js +492 -0
  143. package/dist/k-icon-BZC7dQV0.js.map +1 -0
  144. package/dist/k-nocontent-Bh_yToGh.js +48 -0
  145. package/dist/k-nocontent-Bh_yToGh.js.map +1 -0
  146. package/dist/k-resizable-grid-Ch3iWZaL.js +3157 -0
  147. package/dist/k-resizable-grid-Ch3iWZaL.js.map +1 -0
  148. package/dist/k-standard-layout-CQ1VZoxa.js +5011 -0
  149. package/dist/k-standard-layout-CQ1VZoxa.js.map +1 -0
  150. package/dist/layouts/k-standard-layout.d.ts +16 -0
  151. package/dist/layouts/k-standard-layout.d.ts.map +1 -0
  152. package/dist/parts/index.d.ts +1 -0
  153. package/dist/parts/index.d.ts.map +1 -0
  154. package/dist/parts/index.js +53 -0
  155. package/dist/parts/index.js.map +1 -0
  156. package/dist/parts/k-app.d.ts +11 -0
  157. package/dist/parts/k-app.d.ts.map +1 -0
  158. package/dist/parts/k-container.d.ts +4 -0
  159. package/dist/parts/k-container.d.ts.map +1 -0
  160. package/dist/parts/k-contextmenu.d.ts +38 -0
  161. package/dist/parts/k-contextmenu.d.ts.map +1 -0
  162. package/dist/parts/k-dialog-content.d.ts +9 -0
  163. package/dist/parts/k-dialog-content.d.ts.map +1 -0
  164. package/dist/parts/k-element.d.ts +36 -0
  165. package/dist/parts/k-element.d.ts.map +1 -0
  166. package/dist/parts/k-part.d.ts +96 -0
  167. package/dist/parts/k-part.d.ts.map +1 -0
  168. package/dist/parts/k-resizable-grid.d.ts +31 -0
  169. package/dist/parts/k-resizable-grid.d.ts.map +1 -0
  170. package/dist/parts/k-tabs.d.ts +74 -0
  171. package/dist/parts/k-tabs.d.ts.map +1 -0
  172. package/dist/parts/k-toolbar.d.ts +21 -0
  173. package/dist/parts/k-toolbar.d.ts.map +1 -0
  174. package/dist/widgets/index.d.ts +1 -0
  175. package/dist/widgets/index.d.ts.map +1 -0
  176. package/dist/widgets/index.js +3 -0
  177. package/dist/widgets/index.js.map +1 -0
  178. package/dist/widgets/k-icon.d.ts +10 -0
  179. package/dist/widgets/k-icon.d.ts.map +1 -0
  180. package/dist/widgets/k-nocontent.d.ts +13 -0
  181. package/dist/widgets/k-nocontent.d.ts.map +1 -0
  182. package/dist/widgets/k-widget.d.ts +25 -0
  183. package/dist/widgets/k-widget.d.ts.map +1 -0
  184. package/package.json +81 -0
  185. package/src/api/base-classes.ts +10 -0
  186. package/src/api/constants.ts +3 -0
  187. package/src/api/index.ts +31 -0
  188. package/src/api/services.ts +52 -0
  189. package/src/api/types.ts +46 -0
  190. package/src/commands/files.ts +829 -0
  191. package/src/commands/global.ts +225 -0
  192. package/src/commands/index.ts +4 -0
  193. package/src/commands/version-info.ts +214 -0
  194. package/src/components/index.ts +10 -0
  195. package/src/components/k-app-selector.ts +233 -0
  196. package/src/components/k-app-switcher.ts +126 -0
  197. package/src/components/k-command.ts +236 -0
  198. package/src/components/k-extensions.ts +615 -0
  199. package/src/components/k-fastviews.ts +314 -0
  200. package/src/components/k-filebrowser.ts +442 -0
  201. package/src/components/k-language-selector.ts +166 -0
  202. package/src/components/k-log-terminal.ts +337 -0
  203. package/src/components/k-part-name.ts +54 -0
  204. package/src/components/k-tasks.ts +267 -0
  205. package/src/components/k-workspace-name.ts +56 -0
  206. package/src/contributions/default-ui-contributions.ts +51 -0
  207. package/src/contributions/index.ts +3 -0
  208. package/src/contributions/marketplace-catalog-contributions.ts +6 -0
  209. package/src/core/app-host-config.ts +23 -0
  210. package/src/core/apploader.ts +630 -0
  211. package/src/core/appstate.ts +15 -0
  212. package/src/core/commandregistry.ts +210 -0
  213. package/src/core/config.ts +29 -0
  214. package/src/core/constants.ts +27 -0
  215. package/src/core/contributionregistry.ts +77 -0
  216. package/src/core/di.ts +54 -0
  217. package/src/core/dialogservice.ts +266 -0
  218. package/src/core/editorregistry.ts +303 -0
  219. package/src/core/esmsh-service.ts +404 -0
  220. package/src/core/events.ts +68 -0
  221. package/src/core/extensionregistry.ts +399 -0
  222. package/src/core/filesys.ts +618 -0
  223. package/src/core/i18n.ts +221 -0
  224. package/src/core/index.ts +51 -0
  225. package/src/core/k-utils.ts +11 -0
  226. package/src/core/keybindings.ts +274 -0
  227. package/src/core/logger.ts +187 -0
  228. package/src/core/marketplaceregistry.ts +197 -0
  229. package/src/core/packageinfoservice.ts +56 -0
  230. package/src/core/persistenceservice.ts +15 -0
  231. package/src/core/settingsservice.ts +70 -0
  232. package/src/core/signals.ts +18 -0
  233. package/src/core/taskservice.ts +72 -0
  234. package/src/core/toast.ts +11 -0
  235. package/src/core/tree-utils.ts +24 -0
  236. package/src/dialogs/confirm-dialog.ts +72 -0
  237. package/src/dialogs/index.ts +4 -0
  238. package/src/dialogs/info-dialog.ts +67 -0
  239. package/src/dialogs/navigable-info-dialog.ts +256 -0
  240. package/src/dialogs/prompt-dialog.ts +123 -0
  241. package/src/externals/lit.ts +26 -0
  242. package/src/externals/third-party.ts +9 -0
  243. package/src/externals/webawesome.ts +54 -0
  244. package/src/i18n/extensions.json +39 -0
  245. package/src/i18n/fastviews.json +10 -0
  246. package/src/i18n/filebrowser.json +33 -0
  247. package/src/i18n/index.ts +25 -0
  248. package/src/i18n/logterminal.json +42 -0
  249. package/src/i18n/partname.json +12 -0
  250. package/src/i18n/tasks.json +12 -0
  251. package/src/i18n/workspace.json +12 -0
  252. package/src/icons/icons.txt +3 -0
  253. package/src/icons/js.svg +6 -0
  254. package/src/icons/jupyter.svg +18 -0
  255. package/src/icons/python.svg +15 -0
  256. package/src/index.ts +3 -0
  257. package/src/layouts/k-standard-layout.ts +174 -0
  258. package/src/parts/index.ts +6 -0
  259. package/src/parts/k-app.ts +29 -0
  260. package/src/parts/k-container.ts +4 -0
  261. package/src/parts/k-contextmenu.ts +245 -0
  262. package/src/parts/k-dialog-content.ts +31 -0
  263. package/src/parts/k-element.ts +100 -0
  264. package/src/parts/k-part.ts +158 -0
  265. package/src/parts/k-resizable-grid.ts +366 -0
  266. package/src/parts/k-tabs.ts +574 -0
  267. package/src/parts/k-toolbar.ts +158 -0
  268. package/src/vite-env.d.ts +2 -0
  269. package/src/widgets/index.ts +2 -0
  270. package/src/widgets/k-icon.ts +39 -0
  271. package/src/widgets/k-nocontent.ts +40 -0
  272. package/src/widgets/k-widget.ts +90 -0
@@ -0,0 +1,158 @@
1
+ import {css, html} from 'lit'
2
+ import {customElement, property, state} from 'lit/decorators.js'
3
+ import {KElement} from "./k-element";
4
+ import {styleMap} from 'lit/directives/style-map.js';
5
+ import {
6
+ CommandContribution,
7
+ Contribution,
8
+ ContributionChangeEvent,
9
+ contributionRegistry,
10
+ HTMLContribution,
11
+ TOPIC_CONTRIBUTEIONS_CHANGED
12
+ } from "../core/contributionregistry";
13
+ import {Signal} from '@lit-labs/signals';
14
+ import {unsafeHTML} from "lit/directives/unsafe-html.js";
15
+ import {subscribe} from "../core/events";
16
+
17
+ @customElement('k-toolbar')
18
+ export class KToolbar extends KElement {
19
+ @property()
20
+ private position: "start" | "center" | "end" = "start";
21
+
22
+ @property({type: Boolean, attribute: 'is-editor'})
23
+ private isEditor: boolean = false;
24
+
25
+ @property({attribute: false})
26
+ public partToolbarContent?: any = undefined;
27
+
28
+ @property({attribute: false})
29
+ public partToolbarRenderer?: () => any = undefined;
30
+
31
+ @state()
32
+ private contributions: Contribution[] = [];
33
+
34
+ protected doBeforeUI() {
35
+ const id = this.getAttribute("id");
36
+ if (id) {
37
+ this.loadContributions(id);
38
+ }
39
+
40
+ subscribe(TOPIC_CONTRIBUTEIONS_CHANGED, (event: ContributionChangeEvent) => {
41
+ if (!id) return;
42
+
43
+ const shouldReload = this.matchesTarget(id, event.target);
44
+ if (shouldReload) {
45
+ this.loadContributions(id);
46
+ this.requestUpdate()
47
+ }
48
+ })
49
+ }
50
+
51
+
52
+ private matchesTarget(id: string, target: string): boolean {
53
+ if (target === id) return true;
54
+
55
+ if (!id.includes(':')) return false;
56
+
57
+ const [prefix] = id.split(':');
58
+ if (target === `${prefix}:*`) return true;
59
+
60
+ const targetParts = target.split(':');
61
+ if (targetParts.length === 2) {
62
+ const categoryToken = targetParts[1];
63
+ if (categoryToken === 'system.editors' || categoryToken === '.system.editors') {
64
+ return this.isEditor && id.startsWith(`${prefix}:`);
65
+ }
66
+ }
67
+
68
+ return false;
69
+ }
70
+
71
+ private loadContributions(id: string) {
72
+ const specific = contributionRegistry.getContributions(id);
73
+
74
+ if (!id.includes(':')) {
75
+ this.contributions = specific;
76
+ return;
77
+ }
78
+
79
+ const [prefix] = id.split(':');
80
+ const wildcardId = `${prefix}:*`;
81
+ const wildcard = contributionRegistry.getContributions(wildcardId);
82
+
83
+ const categoryMatches: Contribution[] = [];
84
+
85
+ if (this.isEditor) {
86
+ const allCategories = ['system.editors', '.system.editors'];
87
+ for (const category of allCategories) {
88
+ const categoryId = `${prefix}:${category}`;
89
+ const matches = contributionRegistry.getContributions(categoryId);
90
+ categoryMatches.push(...matches);
91
+ }
92
+ }
93
+
94
+ this.contributions = [...wildcard, ...categoryMatches, ...specific];
95
+ }
96
+
97
+ contributionCreator(contribution: Contribution) {
98
+ if ("command" in contribution) {
99
+ const commandContribution = contribution as CommandContribution
100
+ const showLabel = !!commandContribution.showLabel
101
+ return html`
102
+ <wa-button @click=${() => this.executeCommand(commandContribution.command, commandContribution.params || {})}
103
+ title=${commandContribution.label}
104
+ ?disabled="${(commandContribution.disabled as Signal.Computed<boolean>)?.get()}"
105
+ appearance="plain" size="small">
106
+ <wa-icon name=${commandContribution.icon} label="${commandContribution.label}"></wa-icon>
107
+ ${showLabel ? commandContribution.label : ''}
108
+ </wa-button>
109
+ `
110
+ } else if ("html" in contribution) {
111
+ const contents = (contribution as HTMLContribution).html
112
+ if (contents instanceof Function) {
113
+ return contents()
114
+ }
115
+ return unsafeHTML(contents)
116
+ } else {
117
+ return html`<span>unknown contribution type: ${typeof contribution}</span>`
118
+ }
119
+ }
120
+
121
+ render() {
122
+ const partContent = this.partToolbarRenderer ? this.partToolbarRenderer() :
123
+ (this.partToolbarContent ? this.partToolbarContent : '');
124
+
125
+ return html`
126
+ <div class="toolbar-items" style=${styleMap({"justify-content": this.position})}>
127
+ <slot name="start">
128
+ ${this.contributions.filter(c => c.slot === "start").map(this.contributionCreator.bind(this))}
129
+ </slot>
130
+ ${partContent}
131
+ ${this.contributions.filter(c => c.slot === undefined).map(this.contributionCreator.bind(this))}
132
+ <slot>
133
+ </slot>
134
+ <slot name="end">
135
+ ${this.contributions.filter(c => c.slot === "end").map(this.contributionCreator.bind(this))}
136
+ </slot>
137
+ </div>
138
+ `;
139
+ }
140
+
141
+ static styles = css`
142
+ :host {
143
+ display: flex;
144
+ flex-direction: row;
145
+ }
146
+
147
+ .toolbar-items {
148
+ display: flex;
149
+ flex: 1;
150
+ }
151
+ `
152
+ }
153
+
154
+ declare global {
155
+ interface HTMLElementTagNameMap {
156
+ 'k-toolbar': KToolbar
157
+ }
158
+ }
@@ -0,0 +1,2 @@
1
+ /// <reference types="vite/client" />
2
+
@@ -0,0 +1,2 @@
1
+ import "./k-nocontent"
2
+ import "./k-icon"
@@ -0,0 +1,39 @@
1
+ import {customElement, property} from 'lit/decorators.js'
2
+ import {html, nothing, css} from 'lit';
3
+
4
+ import {KWidget} from "./k-widget";
5
+ import "../core/k-utils";
6
+
7
+ @customElement('k-icon')
8
+ export class KIcon extends KWidget {
9
+
10
+ @property()
11
+ name?: string;
12
+
13
+ @property()
14
+ family?: string = "regular";
15
+
16
+ @property()
17
+ variant?: string;
18
+
19
+ @property()
20
+ label?: string;
21
+
22
+ render() {
23
+ if (!this.name) {
24
+ return ""
25
+ }
26
+ const parts = this.name.trim().split(/ +/)
27
+ const iconName = parts.pop()
28
+ const library = parts.pop()
29
+ return html`
30
+ <wa-icon library="${library || nothing}" variant="${this.variant || nothing}"
31
+ family="${this.family || nothing}" name=${iconName} label="${this.label || this.name || nothing}"></wa-icon>`
32
+ }
33
+
34
+ static styles = css`
35
+ :host {
36
+ display: contents;
37
+ }
38
+ `
39
+ }
@@ -0,0 +1,40 @@
1
+ import {css, html} from 'lit'
2
+ import {customElement, property} from 'lit/decorators.js'
3
+
4
+ import {KWidget} from "./k-widget";
5
+
6
+ @customElement('k-no-content')
7
+ export class KNoContent extends KWidget {
8
+
9
+ @property()
10
+ private message: string = "No content.";
11
+
12
+ @property()
13
+ private icon: string = "info-circle";
14
+
15
+ render() {
16
+ return html`
17
+ <h3>
18
+ <wa-icon name=${this.icon} label="${this.message}"></wa-icon>
19
+ ${this.message}
20
+ </h3>
21
+ `
22
+ }
23
+
24
+ static styles = css`
25
+ :host {
26
+ display: flex;
27
+ margin: 10px;
28
+ }
29
+
30
+ * {
31
+ flex: 1;
32
+ }
33
+ `
34
+ }
35
+
36
+ declare global {
37
+ interface HTMLElementTagNameMap {
38
+ 'k-no-content': KNoContent
39
+ }
40
+ }
@@ -0,0 +1,90 @@
1
+ import {LitElement, PropertyValues} from "lit";
2
+ import {subscribe as event_subscribe, unsubscribe as event_unsubscribe, type SubscriptionToken} from "../core/events";
3
+ import {toastError, toastInfo} from "../core/toast";
4
+ import {commandRegistry, ExecuteParams} from "../core/commandregistry";
5
+ import {Signal, SignalWatcher} from "@lit-labs/signals";
6
+ import {watchSignal} from "../core/signals";
7
+
8
+ Object.defineProperty(LitElement.prototype, "model", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true
12
+ });
13
+
14
+ export abstract class KWidget extends SignalWatcher(LitElement) {
15
+ private signalCleanups = new Set<() => void>();
16
+ private eventSubscriptions = new Set<SubscriptionToken>();
17
+
18
+ connectedCallback() {
19
+ super.connectedCallback();
20
+ this.doBeforeUI()
21
+ }
22
+
23
+ disconnectedCallback() {
24
+ super.disconnectedCallback();
25
+ this.eventSubscriptions.forEach(token => event_unsubscribe(token));
26
+ this.eventSubscriptions.clear();
27
+ this.signalCleanups.forEach(cleanup => cleanup());
28
+ this.signalCleanups.clear();
29
+ }
30
+
31
+ protected subscribe(topic: string, callback: Function): void {
32
+ const token = event_subscribe(topic, callback.bind(this));
33
+ this.eventSubscriptions.add(token);
34
+ }
35
+
36
+ protected showInfo(msg: string) {
37
+ toastInfo(msg)
38
+ }
39
+
40
+ protected showError(msg: string) {
41
+ toastError(msg)
42
+ }
43
+
44
+ protected nobubble(wrap: (event: Event) => void) {
45
+ return (event: Event) => {
46
+ event.stopPropagation();
47
+ wrap.bind(this)(event);
48
+ };
49
+ }
50
+
51
+ protected command(command: string, state: {} = {}) {
52
+ return () => {
53
+ this.executeCommand(command, state)
54
+ };
55
+ }
56
+
57
+ protected executeCommand(command: string, params: ExecuteParams) {
58
+ const execContext = commandRegistry.createExecutionContext(params);
59
+ commandRegistry.execute(command, execContext);
60
+ }
61
+
62
+ protected watch(signal: Signal.State<any> | Signal.Computed<any>, callback: (value: any) => void): void {
63
+ const cleanup = watchSignal(signal as Signal.State<any>, callback.bind(this));
64
+ this.signalCleanups.add(cleanup);
65
+ }
66
+
67
+ protected firstUpdated(_changedProperties: PropertyValues) {
68
+ super.firstUpdated(_changedProperties);
69
+ this.doInitUI()
70
+ }
71
+
72
+ protected updateIdle() {
73
+ requestIdleCallback(() => this.requestUpdate())
74
+ }
75
+
76
+ public updateLater() {
77
+ requestAnimationFrame(() => this.requestUpdate())
78
+ }
79
+
80
+ protected doBeforeUI() {
81
+ }
82
+
83
+ protected doInitUI() {
84
+ }
85
+
86
+ withRefresh(callback: () => void) {
87
+ callback()
88
+ this.updateLater()
89
+ }
90
+ }