@things-factory/help 4.0.14 → 4.0.18
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/client/index.js
CHANGED
|
@@ -6,17 +6,13 @@ import { css, html } from 'lit-element'
|
|
|
6
6
|
import { i18next, localize } from '@things-factory/i18n-base'
|
|
7
7
|
|
|
8
8
|
import Headroom from '@operato/headroom'
|
|
9
|
-
import { HelpStyle } from '../help-style'
|
|
10
9
|
import { connect } from 'pwa-helpers/connect-mixin.js'
|
|
11
|
-
import { md } from '../controller/markdown'
|
|
12
|
-
import { unsafeHTML } from 'lit-html/directives/unsafe-html'
|
|
13
10
|
|
|
14
11
|
class HelpHome extends connect(store)(localize(i18next)(PageView)) {
|
|
15
12
|
static get styles() {
|
|
16
13
|
return [
|
|
17
14
|
ScrollbarStyles,
|
|
18
15
|
HeadroomStyles,
|
|
19
|
-
HelpStyle,
|
|
20
16
|
css`
|
|
21
17
|
:host {
|
|
22
18
|
display: flex;
|
|
@@ -60,47 +56,6 @@ class HelpHome extends connect(store)(localize(i18next)(PageView)) {
|
|
|
60
56
|
|
|
61
57
|
scroll-padding-top: 65px;
|
|
62
58
|
}
|
|
63
|
-
|
|
64
|
-
#toc {
|
|
65
|
-
position: absolute;
|
|
66
|
-
max-width: 250px;
|
|
67
|
-
background-color: var(--theme-white-color);
|
|
68
|
-
padding: var(--padding-default);
|
|
69
|
-
right: var(--margin-wide);
|
|
70
|
-
font: bold var(--fontsize-large) var(--theme-font);
|
|
71
|
-
color: var(--secondary-text-color);
|
|
72
|
-
}
|
|
73
|
-
#toc ul {
|
|
74
|
-
list-style: circle;
|
|
75
|
-
margin: var(--margin-default) 0 0 var(--margin-wide);
|
|
76
|
-
padding: 0;
|
|
77
|
-
}
|
|
78
|
-
#toc a {
|
|
79
|
-
display: inline-block;
|
|
80
|
-
margin-left: -var(--margin-narrow);
|
|
81
|
-
padding: var(--padding-narrow) 0;
|
|
82
|
-
font: normal var(--fontsize-default) var(--theme-font);
|
|
83
|
-
color: var(--secondary-color);
|
|
84
|
-
text-decoration: none;
|
|
85
|
-
cursor: pointer;
|
|
86
|
-
}
|
|
87
|
-
#toc a:hover {
|
|
88
|
-
background-color: var(--theme-white-color);
|
|
89
|
-
text-decoration: underline;
|
|
90
|
-
color: var(--primary-color);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
@media screen and (max-width: 480px) {
|
|
94
|
-
#toc {
|
|
95
|
-
background-color: var(--main-section-background-color);
|
|
96
|
-
border-left: 4px solid var(--primary-color);
|
|
97
|
-
border-bottom: 1px dotted rgba(0, 0, 0, 0.2);
|
|
98
|
-
position: relative;
|
|
99
|
-
width: 100%;
|
|
100
|
-
max-width: initial;
|
|
101
|
-
padding: var(--padding-default) var(--padding-default) var(--padding-default) var(--padding-wide);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
59
|
`
|
|
105
60
|
]
|
|
106
61
|
}
|
|
@@ -108,8 +63,6 @@ class HelpHome extends connect(store)(localize(i18next)(PageView)) {
|
|
|
108
63
|
static get properties() {
|
|
109
64
|
return {
|
|
110
65
|
topic: String,
|
|
111
|
-
_html: String,
|
|
112
|
-
_headings: Array,
|
|
113
66
|
showGotoTop: Boolean
|
|
114
67
|
}
|
|
115
68
|
}
|
|
@@ -121,11 +74,10 @@ class HelpHome extends connect(store)(localize(i18next)(PageView)) {
|
|
|
121
74
|
}
|
|
122
75
|
|
|
123
76
|
render() {
|
|
77
|
+
const src = this.topic && `/helps/${this.topic || 'index'}.md`
|
|
78
|
+
|
|
124
79
|
return html`
|
|
125
|
-
<
|
|
126
|
-
${this.renderToc()}
|
|
127
|
-
${this._html}
|
|
128
|
-
</div>
|
|
80
|
+
<ox-markdown id="content" .src=${src} toc></ox-markdown>
|
|
129
81
|
|
|
130
82
|
<div id="navigation">
|
|
131
83
|
<mwc-icon-button icon="home" @click=${e => navigate('help')} ?disabled=${
|
|
@@ -141,23 +93,6 @@ class HelpHome extends connect(store)(localize(i18next)(PageView)) {
|
|
|
141
93
|
`
|
|
142
94
|
}
|
|
143
95
|
|
|
144
|
-
renderToc() {
|
|
145
|
-
var toc = this._headings || []
|
|
146
|
-
|
|
147
|
-
return toc && toc.length > 0
|
|
148
|
-
? html`
|
|
149
|
-
<div id="toc">
|
|
150
|
-
Table Of Contents
|
|
151
|
-
<ul>
|
|
152
|
-
${toc.map(
|
|
153
|
-
heading => html` <li><a @click=${e => heading?.scrollIntoView()}>${heading.textContent}</a></li> `
|
|
154
|
-
)}
|
|
155
|
-
</ul>
|
|
156
|
-
</div>
|
|
157
|
-
`
|
|
158
|
-
: html``
|
|
159
|
-
}
|
|
160
|
-
|
|
161
96
|
async firstUpdated() {
|
|
162
97
|
var content = this.renderRoot.querySelector('#content')
|
|
163
98
|
content.addEventListener('scroll', e => {
|
|
@@ -177,37 +112,6 @@ class HelpHome extends connect(store)(localize(i18next)(PageView)) {
|
|
|
177
112
|
headroom.init()
|
|
178
113
|
}
|
|
179
114
|
|
|
180
|
-
async updated(changed) {
|
|
181
|
-
if (changed.has('topic')) {
|
|
182
|
-
const baseUrl = `/helps/${this.topic || 'index'}.md`
|
|
183
|
-
const response = await fetch(baseUrl)
|
|
184
|
-
|
|
185
|
-
const content = await response.text()
|
|
186
|
-
|
|
187
|
-
if (!response.ok) {
|
|
188
|
-
this._html = html`
|
|
189
|
-
<h1>Error : ${response.status}</h1>
|
|
190
|
-
<div>${content}</div>
|
|
191
|
-
<a href=${`/help?topic=${this.topic}`}>try again</a>
|
|
192
|
-
`
|
|
193
|
-
} else {
|
|
194
|
-
if (response.headers.get('Content-Type').indexOf('text/markdown') !== -1) {
|
|
195
|
-
this._html = unsafeHTML(
|
|
196
|
-
(await md(content, {
|
|
197
|
-
baseUrl
|
|
198
|
-
})) || ''
|
|
199
|
-
)
|
|
200
|
-
} else {
|
|
201
|
-
this._html = unsafeHTML(content || '')
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (changed.has('_html')) {
|
|
207
|
-
this._headings = Array.from(this.renderRoot.querySelectorAll('#content h2'))
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
115
|
async pageUpdated(changes, lifecycle) {
|
|
212
116
|
if (this.active) {
|
|
213
117
|
this.topic = lifecycle.params['topic'] || 'index'
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import '@material/mwc-icon-button'
|
|
2
|
+
import '@operato/markdown'
|
|
2
3
|
|
|
3
4
|
import { HeadroomStyles, ScrollbarStyles } from '@things-factory/styles'
|
|
4
5
|
import { LitElement, css, html } from 'lit-element'
|
|
5
6
|
import { navigate, store } from '@things-factory/shell'
|
|
6
7
|
|
|
7
8
|
import Headroom from '@operato/headroom'
|
|
8
|
-
import { HelpStyle } from '../help-style'
|
|
9
9
|
import { closeOverlay } from '@things-factory/layout-base'
|
|
10
10
|
import { connect } from 'pwa-helpers/connect-mixin.js'
|
|
11
|
-
import { md } from '../controller/markdown'
|
|
12
|
-
import { unsafeHTML } from 'lit-html/directives/unsafe-html'
|
|
13
11
|
|
|
14
12
|
class HelpPanel extends connect(store)(LitElement) {
|
|
15
13
|
static get properties() {
|
|
16
14
|
return {
|
|
17
15
|
topic: String,
|
|
18
|
-
_html: String,
|
|
19
16
|
historyIndex: Number,
|
|
20
17
|
showGotoTop: Boolean
|
|
21
18
|
}
|
|
@@ -25,7 +22,6 @@ class HelpPanel extends connect(store)(LitElement) {
|
|
|
25
22
|
return [
|
|
26
23
|
ScrollbarStyles,
|
|
27
24
|
HeadroomStyles,
|
|
28
|
-
HelpStyle,
|
|
29
25
|
css`
|
|
30
26
|
:host {
|
|
31
27
|
display: flex;
|
|
@@ -121,7 +117,7 @@ class HelpPanel extends connect(store)(LitElement) {
|
|
|
121
117
|
${!this.showGotoTop
|
|
122
118
|
? html``
|
|
123
119
|
: html` <mwc-icon id="upward" @click=${e => this.gotoTop(e)}>arrow_upward</mwc-icon> `}
|
|
124
|
-
<
|
|
120
|
+
<ox-markdown id="content" .src=${this.topic && `/helps/${this.topic}.md`}></ox-markdown>
|
|
125
121
|
`
|
|
126
122
|
}
|
|
127
123
|
|
|
@@ -148,30 +144,6 @@ class HelpPanel extends connect(store)(LitElement) {
|
|
|
148
144
|
|
|
149
145
|
async updated(changed) {
|
|
150
146
|
if (changed.has('topic')) {
|
|
151
|
-
if (this.topic) {
|
|
152
|
-
const baseUrl = `/helps/${this.topic}.md`
|
|
153
|
-
const response = await fetch(baseUrl)
|
|
154
|
-
const content = await response.text()
|
|
155
|
-
|
|
156
|
-
if (!response.ok) {
|
|
157
|
-
this._html = html`
|
|
158
|
-
<h1>Error : ${response.status}</h1>
|
|
159
|
-
<div>${content}</div>
|
|
160
|
-
<a href=${`/help?topic=${this.topic}`}>try again</a>
|
|
161
|
-
`
|
|
162
|
-
} else {
|
|
163
|
-
if (response.headers.get('Content-Type').indexOf('text/markdown') !== -1) {
|
|
164
|
-
this._html = unsafeHTML(
|
|
165
|
-
(await md(content, {
|
|
166
|
-
baseUrl
|
|
167
|
-
})) || ''
|
|
168
|
-
)
|
|
169
|
-
} else {
|
|
170
|
-
this._html = unsafeHTML(content || '')
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
147
|
if (!this.history) {
|
|
176
148
|
this.history = [this.topic]
|
|
177
149
|
this.historyIndex = 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/help",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.18",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@material/mwc-icon": "^0.25.3",
|
|
28
28
|
"@material/mwc-icon-button": "^0.25.3",
|
|
29
|
-
"@operato/headroom": "^0.2.
|
|
30
|
-
"@
|
|
31
|
-
"@things-factory/
|
|
32
|
-
"
|
|
29
|
+
"@operato/headroom": "^0.2.49",
|
|
30
|
+
"@operato/markdown": "^0.2.49",
|
|
31
|
+
"@things-factory/grist-ui": "^4.0.18",
|
|
32
|
+
"@things-factory/layout-base": "^4.0.18"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "6fc54f287739a57d1926d84dc50baf36156880ba"
|
|
35
35
|
}
|
|
Binary file
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
importScripts('/node_modules/marked/marked.min.js')
|
|
2
|
-
|
|
3
|
-
var TOPIC_OFFSET = '/helps/'.length
|
|
4
|
-
|
|
5
|
-
marked.use({
|
|
6
|
-
renderer: {
|
|
7
|
-
link: function link(href, title, text) {
|
|
8
|
-
var baseUrl = new URL(this.options.baseUrl, location.origin)
|
|
9
|
-
var targetUrl = new URL(href, baseUrl)
|
|
10
|
-
var outside = targetUrl.origin !== location.origin
|
|
11
|
-
|
|
12
|
-
if (!outside) {
|
|
13
|
-
var pathname = targetUrl.pathname
|
|
14
|
-
if (pathname.endsWith('.md') || pathname.endsWith('.markdown')) {
|
|
15
|
-
var url = new URL(location.origin + '/help')
|
|
16
|
-
url.searchParams.append('topic', pathname.slice(TOPIC_OFFSET, pathname.lastIndexOf('.')))
|
|
17
|
-
|
|
18
|
-
href = url.href
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return `<a href="${href}" ${title ? `title="${title}"` : ''} ${outside ? 'target="_blank"' : ''}>${text}</a>`
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
onmessage = e => {
|
|
28
|
-
const { content, options } = e.data
|
|
29
|
-
postMessage(marked.parse(content, options))
|
|
30
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const worker = new Worker('/assets/scripts/markdown-webworker.js')
|
|
2
|
-
const TIMEOUT_LIMIT = 20000
|
|
3
|
-
|
|
4
|
-
export async function md(markdown, options) {
|
|
5
|
-
return new Promise((resolve, reject) => {
|
|
6
|
-
var timeout = setTimeout(() => {
|
|
7
|
-
reject('Marked took too long!')
|
|
8
|
-
}, TIMEOUT_LIMIT)
|
|
9
|
-
|
|
10
|
-
worker.onmessage = e => {
|
|
11
|
-
clearTimeout(timeout)
|
|
12
|
-
resolve(e.data)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
worker.postMessage({
|
|
16
|
-
content: markdown,
|
|
17
|
-
options
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
}
|