@operato/help 0.3.22

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 (49) hide show
  1. package/.editorconfig +29 -0
  2. package/.storybook/main.js +3 -0
  3. package/.storybook/server.mjs +8 -0
  4. package/CHANGELOG.md +260 -0
  5. package/LICENSE +21 -0
  6. package/README.md +75 -0
  7. package/demo/index.html +32 -0
  8. package/dist/src/components/ox-help-icon.d.ts +7 -0
  9. package/dist/src/components/ox-help-icon.js +35 -0
  10. package/dist/src/components/ox-help-icon.js.map +1 -0
  11. package/dist/src/components/ox-inline-help.d.ts +8 -0
  12. package/dist/src/components/ox-inline-help.js +32 -0
  13. package/dist/src/components/ox-inline-help.js.map +1 -0
  14. package/dist/src/components/ox-title-with-help.d.ts +10 -0
  15. package/dist/src/components/ox-title-with-help.js +40 -0
  16. package/dist/src/components/ox-title-with-help.js.map +1 -0
  17. package/dist/src/controller/help.d.ts +2 -0
  18. package/dist/src/controller/help.js +12 -0
  19. package/dist/src/controller/help.js.map +1 -0
  20. package/dist/src/grist/help-decorated-renderer.d.ts +3 -0
  21. package/dist/src/grist/help-decorated-renderer.js +10 -0
  22. package/dist/src/grist/help-decorated-renderer.js.map +1 -0
  23. package/dist/src/help-style.d.ts +1 -0
  24. package/dist/src/help-style.js +122 -0
  25. package/dist/src/help-style.js.map +1 -0
  26. package/dist/src/index.d.ts +5 -0
  27. package/dist/src/index.js +6 -0
  28. package/dist/src/index.js.map +1 -0
  29. package/dist/src/pages/ox-help-home.d.ts +1 -0
  30. package/dist/src/pages/ox-help-home.js +123 -0
  31. package/dist/src/pages/ox-help-home.js.map +1 -0
  32. package/dist/src/viewparts/ox-help-panel.d.ts +2 -0
  33. package/dist/src/viewparts/ox-help-panel.js +214 -0
  34. package/dist/src/viewparts/ox-help-panel.js.map +1 -0
  35. package/dist/tsconfig.tsbuildinfo +1 -0
  36. package/package.json +84 -0
  37. package/src/components/ox-help-icon.ts +34 -0
  38. package/src/components/ox-inline-help.ts +29 -0
  39. package/src/components/ox-title-with-help.ts +39 -0
  40. package/src/controller/help.ts +13 -0
  41. package/src/grist/help-decorated-renderer.ts +19 -0
  42. package/src/help-style.ts +122 -0
  43. package/src/index.ts +5 -0
  44. package/src/pages/ox-help-home.ts +127 -0
  45. package/src/themes/help-theme.css +57 -0
  46. package/src/viewparts/ox-help-panel.ts +213 -0
  47. package/tsconfig.json +23 -0
  48. package/web-dev-server.config.mjs +27 -0
  49. package/web-test-runner.config.mjs +41 -0
@@ -0,0 +1,213 @@
1
+ import '@material/mwc-icon-button'
2
+ import '@operato/markdown/ox-markdown.js'
3
+
4
+ import { css, html, LitElement, PropertyValues } from 'lit'
5
+ import { customElement, property, query, state } from 'lit/decorators.js'
6
+ import { connect } from 'pwa-helpers/connect-mixin.js'
7
+
8
+ import Headroom from '@operato/headroom'
9
+ import { closeOverlay } from '@operato/layout'
10
+ import { navigate, store } from '@operato/shell'
11
+ import { HeadroomStyles, ScrollbarStyles } from '@operato/styles'
12
+
13
+ @customElement('ox-help-panel')
14
+ class HelpPanel extends connect(store)(LitElement) {
15
+ static styles = [
16
+ ScrollbarStyles,
17
+ HeadroomStyles,
18
+ css`
19
+ :host {
20
+ display: flex;
21
+ flex-direction: column;
22
+ background-color: var(--help-panel-background-color);
23
+
24
+ position: relative;
25
+ width: var(--help-panel-width);
26
+ max-height: 90%;
27
+ border-radius: var(--help-panel-border-raidus);
28
+ border: var(--help-panel-border);
29
+ box-shadow: var(--help-panel-box-shadow);
30
+ color: var(--help-panel-color);
31
+ margin: 4px;
32
+
33
+ overflow: hidden;
34
+ }
35
+
36
+ :host(:focus) {
37
+ outline: none;
38
+ }
39
+
40
+ #navigation {
41
+ display: flex;
42
+ position: absolute;
43
+ width: 100%;
44
+ padding: var(--help-navigation-padding);
45
+ border-bottom: var(--help-navigation-bottom);
46
+ background-color: white;
47
+ }
48
+ #navigation mwc-icon-button {
49
+ border-right: var(--help-navigation-icon-border);
50
+ cursor: pointer;
51
+ color: var(--help-icon-color);
52
+ }
53
+
54
+ #close {
55
+ margin-left: auto;
56
+ border-right: 0;
57
+ }
58
+
59
+ #content {
60
+ flex: 1;
61
+ overflow: auto;
62
+ padding: var(--help-panel-content-padding);
63
+ margin: var(--help-panel-margin);
64
+ }
65
+
66
+ #upward {
67
+ --mdc-icon-size: 26px;
68
+ position: absolute;
69
+ bottom: var(--data-list-fab-position-vertical);
70
+ right: var(--data-list-fab-position-horizontal);
71
+ background-color: rgba(255, 255, 255, 0.7);
72
+ border-radius: 20px;
73
+ color: var(--data-list-fab-color);
74
+ box-shadow: var(--data-list-fab-shadow);
75
+ padding: 7px;
76
+ }
77
+
78
+ @media screen and (max-width: 480px) {
79
+ :host {
80
+ height: 100%;
81
+ max-height: 100%;
82
+ margin: 0;
83
+ }
84
+ }
85
+ `
86
+ ]
87
+
88
+ @property({ type: String }) topic!: string
89
+ @property({ type: Boolean }) showGotoTop: boolean = false
90
+
91
+ @state() historyIndex: number = 0
92
+ @state() history: string[] = []
93
+
94
+ @query('#content') content!: HTMLElement
95
+ @query('#navigation') navigation!: HTMLElement
96
+
97
+ render() {
98
+ return html`
99
+ <div id="navigation">
100
+ <mwc-icon-button
101
+ icon="home"
102
+ @click=${() => this.goHome()}
103
+ ?disabled=${this.history[0] === this.history[this.historyIndex]}
104
+ ></mwc-icon-button>
105
+ <mwc-icon-button
106
+ icon="keyboard_arrow_left"
107
+ @click=${() => this.historyBack()}
108
+ ?disabled=${this.historyIndex < 1}
109
+ ></mwc-icon-button>
110
+ <mwc-icon-button
111
+ icon="keyboard_arrow_right"
112
+ @click=${() => this.historyForward()}
113
+ ?disabled=${this.historyIndex >= this.history.length - 1}
114
+ ></mwc-icon-button>
115
+ <mwc-icon-button icon="open_in_new" @click=${() => navigate(`help?topic=${this.topic}`)}></mwc-icon-button>
116
+ <mwc-icon-button icon="close" id="close" @click=${() => closeOverlay('help')}></mwc-icon-button>
117
+ </div>
118
+
119
+ ${!this.showGotoTop
120
+ ? html``
121
+ : html` <mwc-icon id="upward" @click=${(e: Event) => this.gotoTop(e)}>arrow_upward</mwc-icon> `}
122
+ <ox-markdown id="content" .src=${this.topic && `/helps/${this.topic}.md`}></ox-markdown>
123
+ `
124
+ }
125
+
126
+ async firstUpdated() {
127
+ this.setupRouter()
128
+
129
+ this.content.addEventListener('scroll', (e: Event) => {
130
+ this.showGotoTop = (e.target as HTMLElement)?.scrollTop !== 0
131
+ })
132
+
133
+ await this.requestUpdate()
134
+
135
+ var originPaddingTop = parseFloat(getComputedStyle(this.content, null).getPropertyValue('padding-top'))
136
+ this.content.style.paddingTop = this.navigation.clientHeight + originPaddingTop + 'px'
137
+
138
+ var headroom = new Headroom(this.navigation, {
139
+ scroller: this.content
140
+ })
141
+ headroom.init()
142
+ }
143
+
144
+ async updated(changes: PropertyValues<this>) {
145
+ if (changes.has('topic')) {
146
+ if (!this.history) {
147
+ this.history = [this.topic]
148
+ this.historyIndex = 0
149
+ }
150
+ }
151
+
152
+ if (changes.has('historyIndex')) {
153
+ this.topic = this.history[this.historyIndex]
154
+ this.content.scrollTop = 0
155
+ }
156
+ }
157
+
158
+ setupRouter() {
159
+ this.addEventListener('click', e => {
160
+ if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey) {
161
+ return
162
+ }
163
+
164
+ const anchor = e.composedPath().filter(n => (n as HTMLElement).tagName === 'A')[0] as HTMLAnchorElement
165
+ if (!anchor || anchor.target || anchor.hasAttribute('download') || anchor.getAttribute('rel') === 'external') {
166
+ return
167
+ }
168
+
169
+ const href = anchor.href
170
+ const newUrl = new URL(href)
171
+ if (!href || href.indexOf('mailto:') !== -1 || newUrl.origin !== location.origin) {
172
+ return
173
+ }
174
+
175
+ e.preventDefault()
176
+ e.stopPropagation()
177
+
178
+ const pathname = newUrl.pathname
179
+ const topic = newUrl.searchParams?.get('topic')
180
+ if (pathname === '/help' && topic) {
181
+ this.history = [...this.history.slice(0, this.historyIndex + 1), topic]
182
+ this.historyIndex++
183
+ this.topic = topic
184
+ } else {
185
+ navigate(href)
186
+ }
187
+
188
+ return
189
+ })
190
+ }
191
+
192
+ gotoTop(e: Event) {
193
+ this.content.scrollTop = 0
194
+
195
+ e.stopPropagation()
196
+ }
197
+
198
+ goHome() {
199
+ if (!this.history?.[0] || this.history[0] == this.topic) {
200
+ return
201
+ }
202
+ this.history.push(this.history[0])
203
+ this.historyIndex = this.history.length - 1
204
+ }
205
+
206
+ historyBack() {
207
+ this.historyIndex > 0 && this.historyIndex--
208
+ }
209
+
210
+ historyForward() {
211
+ this.history && this.historyIndex < this.history.length - 1 && this.historyIndex++
212
+ }
213
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2018",
4
+ "module": "esnext",
5
+ "moduleResolution": "node",
6
+ "noEmitOnError": true,
7
+ "lib": ["es2017", "dom"],
8
+ "strict": true,
9
+ "esModuleInterop": false,
10
+ "allowSyntheticDefaultImports": true,
11
+ "experimentalDecorators": true,
12
+ "useDefineForClassFields": false,
13
+ "importHelpers": true,
14
+ "outDir": "dist",
15
+ "sourceMap": true,
16
+ "inlineSources": true,
17
+ "rootDir": "./",
18
+ "declaration": true,
19
+ "incremental": true,
20
+ "types": ["node", "mocha"]
21
+ },
22
+ "include": ["**/*.ts"]
23
+ }
@@ -0,0 +1,27 @@
1
+ // import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
2
+
3
+ /** Use Hot Module replacement by adding --hmr to the start command */
4
+ const hmr = process.argv.includes('--hmr');
5
+
6
+ export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
7
+ open: '/demo/',
8
+ /** Use regular watch mode if HMR is not enabled. */
9
+ watch: !hmr,
10
+ /** Resolve bare module imports */
11
+ nodeResolve: {
12
+ exportConditions: ['browser', 'development'],
13
+ },
14
+
15
+ /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
16
+ // esbuildTarget: 'auto'
17
+
18
+ /** Set appIndex to enable SPA routing */
19
+ // appIndex: 'demo/index.html',
20
+
21
+ plugins: [
22
+ /** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
23
+ // hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.litElement] }),
24
+ ],
25
+
26
+ // See documentation for all available options
27
+ });
@@ -0,0 +1,41 @@
1
+ // import { playwrightLauncher } from '@web/test-runner-playwright';
2
+
3
+ const filteredLogs = ['Running in dev mode', 'lit-html is in dev mode'];
4
+
5
+ export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
6
+ /** Test files to run */
7
+ files: 'dist/test/**/*.test.js',
8
+
9
+ /** Resolve bare module imports */
10
+ nodeResolve: {
11
+ exportConditions: ['browser', 'development'],
12
+ },
13
+
14
+ /** Filter out lit dev mode logs */
15
+ filterBrowserLogs(log) {
16
+ for (const arg of log.args) {
17
+ if (typeof arg === 'string' && filteredLogs.some(l => arg.includes(l))) {
18
+ return false;
19
+ }
20
+ }
21
+ return true;
22
+ },
23
+
24
+ /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
25
+ // esbuildTarget: 'auto',
26
+
27
+ /** Amount of browsers to run concurrently */
28
+ // concurrentBrowsers: 2,
29
+
30
+ /** Amount of test files per browser to test concurrently */
31
+ // concurrency: 1,
32
+
33
+ /** Browsers to run tests on */
34
+ // browsers: [
35
+ // playwrightLauncher({ product: 'chromium' }),
36
+ // playwrightLauncher({ product: 'firefox' }),
37
+ // playwrightLauncher({ product: 'webkit' }),
38
+ // ],
39
+
40
+ // See documentation for all available options
41
+ });