@record-evolution/widget-markdown 1.0.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/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@record-evolution/widget-markdown",
3
+ "description": "Webcomponent widget-markdown following open-wc recommendations",
4
+ "license": "MIT",
5
+ "author": "widget-markdown",
6
+ "version": "1.0.1",
7
+ "type": "module",
8
+ "main": "dist/widget-markdown.js",
9
+ "types": "dist/src/widget-markdown.d.ts",
10
+ "files": [
11
+ "dist",
12
+ "src",
13
+ "thumbnail.png"
14
+ ],
15
+ "scripts": {
16
+ "analyze": "cem analyze --litelement",
17
+ "start": "concurrently -k -r \"npm run watch\" \"wds\"",
18
+ "build": "rollup -c rollup.config.js",
19
+ "watch": "rollup -w -c rollup.config.js",
20
+ "link": "npm link && cd ../RESWARM/frontend && npm link @record-evolution/widget-markdown",
21
+ "unlink": "npm unlink --global && cd ../RESWARM/frontend && npm unlink @record-evolution/widget-markdown && npm i @record-evolution/widget-markdown",
22
+ "types": "cat src/definition-schema.json | json2ts > src/definition-schema.d.ts",
23
+ "release": "npm run build && npm run types && npm version patch --tag-version-prefix='' && git push && git push --tag && npm run build"
24
+ },
25
+ "dependencies": {
26
+ "github-markdown-css": "^5.8.1",
27
+ "highlight.js": "^11.11.1",
28
+ "lit": "^3.3.1",
29
+ "marked": "^16.3.0",
30
+ "marked-highlight": "^2.2.2"
31
+ },
32
+ "devDependencies": {
33
+ "@custom-elements-manifest/analyzer": "^0.10.4",
34
+ "@rollup/plugin-babel": "^6.0.4",
35
+ "@rollup/plugin-commonjs": "^28.0.6",
36
+ "@rollup/plugin-node-resolve": "^16.0.1",
37
+ "@rollup/plugin-replace": "^6.0.2",
38
+ "@rollup/plugin-typescript": "^12.1.3",
39
+ "@web/dev-server": "^0.4.6",
40
+ "concurrently": "^9.1.2",
41
+ "json-schema-to-typescript": "^15.0.4",
42
+ "rollup-plugin-string": "^3.0.0",
43
+ "tslib": "^2.8.1",
44
+ "typescript": "^5.8.3"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/RecordEvolution/widget-markdown.git"
49
+ },
50
+ "keywords": [
51
+ "widget",
52
+ "textbox"
53
+ ],
54
+ "bugs": {
55
+ "url": "https://github.com/RecordEvolution/widget-markdown/issues"
56
+ },
57
+ "homepage": "https://github.com/RecordEvolution/widget-markdown#readme"
58
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "markdown": "# Markdown Showcase\n\n## Text formatting\nNormal, **bold**, *italic*, ~~strikethrough~~, and `inline code`.\n\n> A blockquote with some *emphasis* and **bold**.\n\n---\n\n## Links & Images\n\n![Placeholder image](https://res.cloudinary.com/dk8bhmsdz/image/upload/c_pad,w_500/v1747230890/samples/imagecon-group.jpg)\n\n[Google](https://google.com)\n\n## Lists\n\n- Unordered item\n - Nested item\n- Another item\n\n1. Ordered list\n2. Second item\n 1. Nested ordered\n 2. Another\n\n---\n\n---\n\n## Code blocks\n\n```python\ndef greet(name):\n print(f\"Hello, {name}!\")\n\ngreet(\"Markdown\")\n```\n\n---\n\n## Tables\n\n| Name | Age | Role |\n|:---------|:---:|-------------:|\n| Alice | 25 | Developer |\n| Bob | 30 | Designer |\n| Charlie | 28 | Product Mgr |\n\n---\n\n## Task lists\n\n- [x] Write Markdown\n- [ ] Preview it\n- [ ] Share it\n\n---\n\n## \n"
3
+ }
@@ -0,0 +1,27 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * This file was automatically generated by json-schema-to-typescript.
4
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5
+ * and run json-schema-to-typescript to regenerate this file.
6
+ */
7
+
8
+ export type FontSize = string;
9
+ export type FontWeight = number;
10
+
11
+ export interface TextboxConfiguration {
12
+ markdown?: Markdown;
13
+ fontSize?: FontSize;
14
+ fontWeight?: FontWeight;
15
+ color?: FontColor;
16
+ backgroundColor?: BackgroundColor;
17
+ [k: string]: unknown;
18
+ }
19
+ export interface Markdown {
20
+ [k: string]: unknown;
21
+ }
22
+ export interface FontColor {
23
+ [k: string]: unknown;
24
+ }
25
+ export interface BackgroundColor {
26
+ [k: string]: unknown;
27
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "title": "Textbox Configuration",
3
+ "type": "object",
4
+ "properties": {
5
+ "markdown": {
6
+ "title": "Markdown",
7
+ "order": 1,
8
+ "type": "textarea"
9
+ },
10
+ "fontSize": {
11
+ "title": "Font Size",
12
+ "order": 2,
13
+ "dataDrivenDisabled": true,
14
+ "type": "string"
15
+ },
16
+ "fontWeight": {
17
+ "title": "Font Weight",
18
+ "order": 3,
19
+ "dataDrivenDisabled": true,
20
+ "type": "number"
21
+ },
22
+ "color": {
23
+ "title": "Font Color",
24
+ "order": 4,
25
+ "type": "color",
26
+ "color": true
27
+ },
28
+ "backgroundColor": {
29
+ "title": "Background Color",
30
+ "order": 5,
31
+ "type": "color",
32
+ "color": true
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,163 @@
1
+ import { html, css, LitElement, PropertyValues } from 'lit'
2
+ import { unsafeHTML } from 'lit/directives/unsafe-html.js'
3
+ import { unsafeCSS } from 'lit'
4
+ import { Marked } from 'marked'
5
+ import { markedHighlight } from 'marked-highlight'
6
+
7
+ import hljs from 'highlight.js/lib/core'
8
+ import shell from 'highlight.js/lib/languages/shell'
9
+ import python from 'highlight.js/lib/languages/python'
10
+ import javascript from 'highlight.js/lib/languages/javascript'
11
+ import plaintext from 'highlight.js/lib/languages/plaintext'
12
+ import typescript from 'highlight.js/lib/languages/typescript'
13
+ import json from 'highlight.js/lib/languages/json'
14
+ import cssLang from 'highlight.js/lib/languages/css'
15
+ // @ts-ignore - virtual import returns a string at build time
16
+ import highlightCSS from 'highlight.js/styles/github.css'
17
+ // GitHub Markdown CSS imported as string via rollup-plugin-string
18
+ // The user requested: import md from 'github-markdown-css'
19
+ // We'll honor that path (package provides github-markdown.css entry)
20
+ // @ts-ignore - virtual import returns a string at build time
21
+ import githubCss from 'github-markdown-css/github-markdown.css'
22
+ import { customElement, property, state } from 'lit/decorators.js'
23
+ import { TextboxConfiguration } from './definition-schema.js'
24
+
25
+ hljs.registerLanguage('shell', shell)
26
+ hljs.registerLanguage('bash', shell)
27
+ hljs.registerLanguage('python', python)
28
+ hljs.registerLanguage('javascript', javascript)
29
+ hljs.registerLanguage('js', javascript)
30
+ hljs.registerLanguage('typescript', typescript)
31
+ hljs.registerLanguage('ts', typescript)
32
+ hljs.registerLanguage('json', json)
33
+ hljs.registerLanguage('css', cssLang)
34
+ hljs.registerLanguage('plaintext', plaintext)
35
+
36
+ type Theme = {
37
+ theme_name: string
38
+ theme_object: any
39
+ }
40
+
41
+ @customElement('widget-markdown-versionplaceholder')
42
+ export class WidgetMarkdown extends LitElement {
43
+ @property({ type: Object })
44
+ inputData?: TextboxConfiguration
45
+
46
+ @property({ type: Object })
47
+ theme?: Theme
48
+
49
+ @state() private themeBgColor?: string
50
+ @state() private themeTitleColor?: string
51
+ @state() private themeSubtitleColor?: string
52
+
53
+ version: string = 'versionplaceholder'
54
+ marked: Marked
55
+
56
+ constructor() {
57
+ super()
58
+ this.marked = new Marked(
59
+ markedHighlight({
60
+ emptyLangClass: 'hljs',
61
+ langPrefix: 'hljs language-',
62
+ highlight(code, lang, info) {
63
+ const language = hljs.getLanguage(lang) ? lang : 'plaintext'
64
+ return hljs.highlight(code, { language }).value
65
+ }
66
+ })
67
+ )
68
+ }
69
+
70
+ update(changedProperties: Map<string, any>) {
71
+ if (changedProperties.has('theme')) {
72
+ this.registerTheme(this.theme)
73
+ }
74
+
75
+ super.update(changedProperties)
76
+ // if (changedProperties.has('inputData') && this.inputData) {
77
+ // if (this.shadowRoot) {
78
+ // for (const codeBlock of Array.from(this.shadowRoot.querySelectorAll('pre code'))) {
79
+ // hljs.highlightBlock(codeBlock as HTMLElement)
80
+ // }
81
+ // }
82
+ // }
83
+ }
84
+
85
+ protected firstUpdated(_changedProperties: PropertyValues): void {
86
+ this.registerTheme(this.theme)
87
+ }
88
+
89
+ registerTheme(theme?: Theme) {
90
+ const cssTextColor = getComputedStyle(this).getPropertyValue('--re-text-color').trim()
91
+ const cssBgColor = getComputedStyle(this).getPropertyValue('--re-tile-background-color').trim()
92
+ this.themeBgColor = cssBgColor || this.theme?.theme_object?.backgroundColor
93
+ this.themeTitleColor = cssTextColor || this.theme?.theme_object?.title?.textStyle?.color
94
+ this.themeSubtitleColor =
95
+ cssTextColor || this.theme?.theme_object?.title?.subtextStyle?.color || this.themeTitleColor
96
+ }
97
+
98
+ static styles = [
99
+ unsafeCSS(githubCss),
100
+ unsafeCSS(highlightCSS),
101
+ css`
102
+ :host {
103
+ display: block;
104
+ font-family: sans-serif;
105
+ box-sizing: border-box;
106
+ margin: auto;
107
+ }
108
+
109
+ .paging:not([active]) {
110
+ display: none !important;
111
+ }
112
+
113
+ .wrapper {
114
+ display: flex;
115
+ flex-direction: column;
116
+ width: 100%;
117
+ padding: 12px;
118
+ box-sizing: border-box;
119
+ }
120
+
121
+ h2 {
122
+ margin: 0;
123
+ padding: 0px;
124
+ }
125
+
126
+ h3 {
127
+ margin: 0;
128
+ padding: 12px 0px;
129
+ }
130
+
131
+ .markdown-body {
132
+ background: transparent;
133
+ color: inherit;
134
+ font-family: inherit;
135
+ width: 100%;
136
+ padding: 12px;
137
+ box-sizing: border-box;
138
+ }
139
+
140
+ .markdown-body table tr {
141
+ background-color: transparent !important;
142
+ }
143
+ `
144
+ ]
145
+
146
+ render() {
147
+ const mdText: string = String(this.inputData?.markdown ?? '')
148
+ const mdHtml: string = this.marked.parse(mdText) as string
149
+ return html`
150
+ <div class="wrapper" style="background-color: ${this.themeBgColor}">
151
+ <div
152
+ class="paging markdown-body"
153
+ ?active=${this.inputData?.markdown}
154
+ style="font-size: ${this.inputData?.fontSize};
155
+ font-weight: ${this.inputData?.fontWeight};
156
+ color: ${this.inputData?.color || this.themeTitleColor};"
157
+ >
158
+ ${unsafeHTML(mdHtml)}
159
+ </div>
160
+ </div>
161
+ `
162
+ }
163
+ }
package/thumbnail.png ADDED
Binary file