@operato/property-editor 0.2.3 → 0.2.33

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 (52) hide show
  1. package/.storybook/main.js +2 -2
  2. package/.storybook/server.mjs +4 -4
  3. package/CHANGELOG.md +13 -6
  4. package/LICENSE +2 -2
  5. package/README.md +26 -7
  6. package/custom-elements.json +317 -0
  7. package/demo/index.html +18 -4
  8. package/dist/src/index.d.ts +1 -3
  9. package/dist/src/index.js +1 -3
  10. package/dist/src/index.js.map +1 -1
  11. package/dist/src/ox-property-editor.d.ts +28 -0
  12. package/dist/src/ox-property-editor.js +161 -0
  13. package/dist/src/ox-property-editor.js.map +1 -0
  14. package/dist/stories/index.stories.d.ts +1 -1
  15. package/dist/stories/index.stories.js +11 -15
  16. package/dist/stories/index.stories.js.map +1 -1
  17. package/dist/test/property-editor.test.d.ts +1 -0
  18. package/dist/test/property-editor.test.js +24 -0
  19. package/dist/test/property-editor.test.js.map +1 -0
  20. package/dist/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +14 -33
  22. package/src/index.ts +1 -3
  23. package/src/ox-property-editor.ts +158 -0
  24. package/stories/index.stories.ts +30 -38
  25. package/test/property-editor.test.ts +34 -0
  26. package/tsconfig.json +2 -2
  27. package/web-dev-server.config.mjs +9 -8
  28. package/web-test-runner.config.mjs +7 -19
  29. package/.editorconfig +0 -29
  30. package/demo/index-3dish.html +0 -22
  31. package/demo/index-angle.html +0 -31
  32. package/demo/index-button-radio.html +0 -30
  33. package/dist/src/property-3dish.d.ts +0 -30
  34. package/dist/src/property-3dish.js +0 -140
  35. package/dist/src/property-3dish.js.map +0 -1
  36. package/dist/src/property-angle.d.ts +0 -14
  37. package/dist/src/property-angle.js +0 -56
  38. package/dist/src/property-angle.js.map +0 -1
  39. package/dist/src/property-buttons-radio.d.ts +0 -28
  40. package/dist/src/property-buttons-radio.js +0 -90
  41. package/dist/src/property-buttons-radio.js.map +0 -1
  42. package/dist/src/property-stack.d.ts +0 -21
  43. package/dist/src/property-stack.js +0 -108
  44. package/dist/src/property-stack.js.map +0 -1
  45. package/dist/test/property-angle.test.d.ts +0 -1
  46. package/dist/test/property-angle.test.js +0 -23
  47. package/dist/test/property-angle.test.js.map +0 -1
  48. package/src/property-3dish.ts +0 -150
  49. package/src/property-angle.ts +0 -56
  50. package/src/property-buttons-radio.ts +0 -87
  51. package/src/property-stack.ts +0 -109
  52. package/test/property-angle.test.ts +0 -32
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@operato/property-editor",
3
- "description": "Webcomponent property-editor following open-wc recommendations",
3
+ "version": "0.2.33",
4
+ "description": "Webcomponent for property-editor following open-wc recommendations",
5
+ "author": "heartyoh",
4
6
  "license": "MIT",
5
- "author": "property-editor",
6
- "version": "0.2.3",
7
7
  "main": "dist/src/index.js",
8
8
  "module": "dist/src/index.js",
9
9
  "publishConfig": {
@@ -15,9 +15,7 @@
15
15
  "url": "git+https://github.com/hatiolab/operato.git",
16
16
  "directory": "webcomponents/property-editor"
17
17
  },
18
- "exports": {
19
- ".": "./dist/src/index.js"
20
- },
18
+ "exports": {},
21
19
  "scripts": {
22
20
  "analyze": "cem analyze --litelement",
23
21
  "start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
@@ -31,13 +29,20 @@
31
29
  "storybook:build": "tsc && npm run analyze -- --exclude dist && build-storybook"
32
30
  },
33
31
  "dependencies": {
34
- "lit": "^2.0.2"
32
+ "lit": "^2.0.2",
33
+ "lodash-es": "^4.17.21"
35
34
  },
36
35
  "devDependencies": {
37
36
  "@custom-elements-manifest/analyzer": "^0.4.17",
38
37
  "@hatiolab/prettier-config": "^1.0.0",
38
+ "@hatiolab/things-scene": "^2.7.17",
39
+ "@material/mwc-fab": "^0.25.3",
40
+ "@material/mwc-icon": "^0.25.3",
39
41
  "@open-wc/eslint-config": "^4.3.0",
40
42
  "@open-wc/testing": "next",
43
+ "@types/bwip-js": "^2.1.1",
44
+ "@types/lodash-es": "^4.17.5",
45
+ "@types/w3c-web-usb": "^1.0.5",
41
46
  "@typescript-eslint/eslint-plugin": "^4.33.0",
42
47
  "@typescript-eslint/parser": "^4.33.0",
43
48
  "@web/dev-server": "^0.1.25",
@@ -50,33 +55,9 @@
50
55
  "lint-staged": "^10.5.4",
51
56
  "prettier": "^2.4.1",
52
57
  "tslib": "^2.3.1",
53
- "typescript": "^4.4.4"
58
+ "typescript": "^4.5.2"
54
59
  },
55
60
  "customElements": "custom-elements.json",
56
- "eslintConfig": {
57
- "parser": "@typescript-eslint/parser",
58
- "extends": [
59
- "@open-wc",
60
- "prettier"
61
- ],
62
- "plugins": [
63
- "@typescript-eslint"
64
- ],
65
- "rules": {
66
- "no-unused-vars": "off",
67
- "@typescript-eslint/no-unused-vars": [
68
- "error"
69
- ],
70
- "import/no-unresolved": "off",
71
- "import/extensions": [
72
- "error",
73
- "always",
74
- {
75
- "ignorePackages": true
76
- }
77
- ]
78
- }
79
- },
80
61
  "prettier": "@hatiolab/prettier-config",
81
62
  "husky": {
82
63
  "hooks": {
@@ -89,5 +70,5 @@
89
70
  "prettier --write"
90
71
  ]
91
72
  },
92
- "gitHead": "b2a5e8cdd0c132d243229eccd448d513471e7e9a"
73
+ "gitHead": "8ed67ce8ff4339971858534ff8f01fd04c25315e"
93
74
  }
package/src/index.ts CHANGED
@@ -1,3 +1 @@
1
- export * from './property-angle'
2
- export * from './property-3dish'
3
- export * from './property-buttons-radio'
1
+ export * from './ox-property-editor'
@@ -0,0 +1,158 @@
1
+ import { LitElement, css, html } from 'lit'
2
+ import { property, state } from 'lit/decorators.js'
3
+
4
+ import deepClone from 'lodash/cloneDeep'
5
+
6
+ export class OxPropertyEditor extends LitElement {
7
+ static registry: { [type: string]: string } = {}
8
+
9
+ public static register(types: { [type: string]: string }) {
10
+ Object.keys(types).forEach(type => {
11
+ OxPropertyEditor.registry[type] = types[type]
12
+ })
13
+ }
14
+
15
+ public static getEditor(type: string): string {
16
+ return OxPropertyEditor.registry[type]
17
+ }
18
+
19
+ static styles = [
20
+ css`
21
+ :host {
22
+ margin: 5px;
23
+
24
+ display: grid;
25
+ grid-template-columns: repeat(10, 1fr);
26
+ grid-gap: 5px;
27
+
28
+ align-items: center;
29
+
30
+ color: var(--property-sidebar-fieldset-legend-color);
31
+ }
32
+
33
+ :host > * {
34
+ box-sizing: border-box;
35
+
36
+ grid-column: span 7;
37
+ order: 2;
38
+
39
+ align-self: stretch;
40
+ }
41
+
42
+ :host > label {
43
+ grid-column: span 3;
44
+ order: 1;
45
+
46
+ text-align: right;
47
+
48
+ font-size: 0.8em;
49
+ line-height: 2;
50
+ text-transform: capitalize;
51
+
52
+ align-self: center;
53
+ }
54
+
55
+ :host > input[type='checkbox'] ~ label {
56
+ grid-column: span 6;
57
+ order: 2;
58
+
59
+ text-align: left;
60
+ }
61
+
62
+ :host > select,
63
+ :host > input[type='text'],
64
+ :host > input[type='number'] {
65
+ border: 1px solid rgba(0, 0, 0, 0.2);
66
+ }
67
+
68
+ :host > legend {
69
+ grid-column: 1 / -1;
70
+
71
+ display: inline-block;
72
+
73
+ text-align: left;
74
+ text-transform: capitalize;
75
+ }
76
+
77
+ :host > [fullwidth] {
78
+ grid-column: 1 / -1;
79
+ }
80
+
81
+ :host > input[type='checkbox'] {
82
+ grid-column: span 4;
83
+ order: 1;
84
+
85
+ justify-self: end;
86
+ align-self: center;
87
+ }
88
+ `
89
+ ]
90
+
91
+ @property({ type: Object }) value: any
92
+ @property({ type: String }) type!: string
93
+ @property({ type: String }) label!: string
94
+ @property({ type: String }) placeholder?: string
95
+ @property({ type: Object }) property: any
96
+ @property({ type: Object }) host: any
97
+ @property({ type: Object }) observe?: (value: any) => void
98
+
99
+ connectedCallback() {
100
+ super.connectedCallback()
101
+
102
+ this.renderRoot.addEventListener('change', this._valueChanged.bind(this))
103
+ }
104
+
105
+ editorTemplate(props: { [key: string]: any }) {
106
+ return html``
107
+ }
108
+
109
+ render() {
110
+ return html`
111
+ ${this.editorTemplate(this)}
112
+ ${this.label
113
+ ? html`
114
+ <label for="editor">
115
+ <i18n-msg msgid=${this._computeLabelId(this.label)}>${this.label}</i18n-msg>
116
+ </label>
117
+ `
118
+ : html``}
119
+ `
120
+ }
121
+
122
+ @state() __by_me = false
123
+
124
+ shouldUpdate(changedProperties: any) {
125
+ if (this.__by_me) {
126
+ return false
127
+ }
128
+
129
+ if (changedProperties.has('value')) {
130
+ this.__by_me = true
131
+ this.value = deepClone(this.value)
132
+ this.__by_me = false
133
+ }
134
+
135
+ return true
136
+ }
137
+
138
+ get valueProperty() {
139
+ return 'value'
140
+ }
141
+
142
+ _computeLabelId(label: string) {
143
+ if (label.indexOf('label.') >= 0) return label
144
+
145
+ return 'label.' + label
146
+ }
147
+
148
+ _valueChanged(e: Event) {
149
+ e.stopPropagation()
150
+
151
+ this.value = deepClone((e.target as any)[this.valueProperty])
152
+
153
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
154
+
155
+ if (!this.observe) return
156
+ this.observe.call(this, this.value)
157
+ }
158
+ }
@@ -1,60 +1,52 @@
1
- import { html, TemplateResult } from 'lit';
2
- import '../src/property-editor.js';
1
+ import '../index.js'
2
+
3
+ import { TemplateResult, html } from 'lit'
3
4
 
4
5
  export default {
5
6
  title: 'PropertyEditor',
6
- component: 'property-editor',
7
+ component: 'ox-property-editor',
7
8
  argTypes: {
8
9
  title: { control: 'text' },
9
10
  counter: { control: 'number' },
10
- textColor: { control: 'color' },
11
- },
12
- };
11
+ textColor: { control: 'color' }
12
+ }
13
+ }
13
14
 
14
15
  interface Story<T> {
15
- (args: T): TemplateResult;
16
- args?: Partial<T>;
17
- argTypes?: Record<string, unknown>;
16
+ (args: T): TemplateResult
17
+ args?: Partial<T>
18
+ argTypes?: Record<string, unknown>
18
19
  }
19
20
 
20
21
  interface ArgTypes {
21
- title?: string;
22
- counter?: number;
23
- textColor?: string;
24
- slot?: TemplateResult;
22
+ title?: string
23
+ counter?: number
24
+ textColor?: string
25
+ slot?: TemplateResult
25
26
  }
26
27
 
27
- const Template: Story<ArgTypes> = ({
28
- title = 'Hello world',
29
- counter = 5,
30
- textColor,
31
- slot,
32
- }: ArgTypes) => html`
33
- <property-editor
34
- style="--property-editor-text-color: ${textColor || 'black'}"
35
- .title=${title}
36
- .counter=${counter}
37
- >
28
+ const Template: Story<ArgTypes> = ({ title = 'Hello world', counter = 5, textColor, slot }: ArgTypes) => html`
29
+ <ox-board-viewer style="--board-viewer-text-color: ${textColor || 'black'}" .title=${title} .counter=${counter}>
38
30
  ${slot}
39
- </property-editor>
40
- `;
31
+ </ox-board-viewer>
32
+ `
41
33
 
42
- export const Regular = Template.bind({});
34
+ export const Regular = Template.bind({})
43
35
 
44
- export const CustomTitle = Template.bind({});
36
+ export const CustomTitle = Template.bind({})
45
37
  CustomTitle.args = {
46
- title: 'My title',
47
- };
38
+ title: 'My title'
39
+ }
48
40
 
49
- export const CustomCounter = Template.bind({});
41
+ export const CustomCounter = Template.bind({})
50
42
  CustomCounter.args = {
51
- counter: 123456,
52
- };
43
+ counter: 123456
44
+ }
53
45
 
54
- export const SlottedContent = Template.bind({});
46
+ export const SlottedContent = Template.bind({})
55
47
  SlottedContent.args = {
56
- slot: html`<p>Slotted content</p>`,
57
- };
48
+ slot: html`<p>Slotted content</p>`
49
+ }
58
50
  SlottedContent.argTypes = {
59
- slot: { table: { disable: true } },
60
- };
51
+ slot: { table: { disable: true } }
52
+ }
@@ -0,0 +1,34 @@
1
+ import '../src/ox-property-editor'
2
+
3
+ import { expect, fixture } from '@open-wc/testing'
4
+
5
+ import { OxPropertyEditor } from '../src/ox-property-editor'
6
+ import { html } from 'lit'
7
+
8
+ describe('OxPropertyEditor', () => {
9
+ it('has a default title "Hey there" and counter 5', async () => {
10
+ const el = await fixture<OxPropertyEditor>(html` <ox-property-editor></ox-property-editor> `)
11
+
12
+ // expect(el.title).to.equal('Hey there')
13
+ // expect(el.counter).to.equal(5)
14
+ })
15
+
16
+ it('increases the counter on button click', async () => {
17
+ const el = await fixture<OxPropertyEditor>(html` <ox-property-editor></ox-property-editor> `)
18
+ el.renderRoot!.querySelector('button')!.click()
19
+
20
+ // expect(el.counter).to.equal(6)
21
+ })
22
+
23
+ it('can override the title via attribute', async () => {
24
+ const el = await fixture<OxPropertyEditor>(html` <property-editor title="attribute title"></ox-property-editor> `)
25
+
26
+ expect(el.title).to.equal('attribute title')
27
+ })
28
+
29
+ it('passes the a11y audit', async () => {
30
+ const el = await fixture<OxPropertyEditor>(html` <ox-property-editor></ox-property-editor> `)
31
+
32
+ await expect(el).shadowDom.to.be.accessible()
33
+ })
34
+ })
package/tsconfig.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "rootDir": "./",
17
17
  "declaration": true,
18
18
  "incremental": true,
19
- "types": ["node", "mocha", "three"]
19
+ "types": ["node", "mocha"]
20
20
  },
21
- "include": ["**/*.ts"]
21
+ "include": ["**/*.ts", "*.d.ts"]
22
22
  }
@@ -1,16 +1,12 @@
1
1
  // import { hmrPlugin, presets } from '@open-wc/dev-server-hmr';
2
2
 
3
3
  /** Use Hot Module replacement by adding --hmr to the start command */
4
- const hmr = process.argv.includes('--hmr');
4
+ const hmr = process.argv.includes('--hmr')
5
5
 
6
6
  export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
7
+ nodeResolve: true,
7
8
  open: '/demo/',
8
- /** Use regular watch mode if HMR is not enabled. */
9
9
  watch: !hmr,
10
- /** Resolve bare module imports */
11
- nodeResolve: {
12
- exportConditions: ['browser', 'development'],
13
- },
14
10
 
15
11
  /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
16
12
  // esbuildTarget: 'auto'
@@ -18,10 +14,15 @@ export default /** @type {import('@web/dev-server').DevServerConfig} */ ({
18
14
  /** Set appIndex to enable SPA routing */
19
15
  // appIndex: 'demo/index.html',
20
16
 
17
+ /** Confgure bare import resolve plugin */
18
+ // nodeResolve: {
19
+ // exportConditions: ['browser', 'development']
20
+ // },
21
+
21
22
  plugins: [
22
23
  /** Use Hot Module Replacement by uncommenting. Requires @open-wc/dev-server-hmr plugin */
23
24
  // hmr && hmrPlugin({ exclude: ['**/*/node_modules/**/*'], presets: [presets.litElement] }),
24
- ],
25
+ ]
25
26
 
26
27
  // See documentation for all available options
27
- });
28
+ })
@@ -1,29 +1,17 @@
1
1
  // import { playwrightLauncher } from '@web/test-runner-playwright';
2
2
 
3
- const filteredLogs = ['Running in dev mode', 'lit-html is in dev mode'];
4
-
5
3
  export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
6
- /** Test files to run */
7
4
  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
- },
5
+ nodeResolve: true
23
6
 
24
7
  /** Compile JS for older browsers. Requires @web/dev-server-esbuild plugin */
25
8
  // esbuildTarget: 'auto',
26
9
 
10
+ /** Confgure bare import resolve plugin */
11
+ // nodeResolve: {
12
+ // exportConditions: ['browser', 'development']
13
+ // },
14
+
27
15
  /** Amount of browsers to run concurrently */
28
16
  // concurrentBrowsers: 2,
29
17
 
@@ -38,4 +26,4 @@ export default /** @type {import("@web/test-runner").TestRunnerConfig} */ ({
38
26
  // ],
39
27
 
40
28
  // See documentation for all available options
41
- });
29
+ })
package/.editorconfig DELETED
@@ -1,29 +0,0 @@
1
- # EditorConfig helps developers define and maintain consistent
2
- # coding styles between different editors and IDEs
3
- # editorconfig.org
4
-
5
- root = true
6
-
7
-
8
- [*]
9
-
10
- # Change these settings to your own preference
11
- indent_style = space
12
- indent_size = 2
13
-
14
- # We recommend you to keep these unchanged
15
- end_of_line = lf
16
- charset = utf-8
17
- trim_trailing_whitespace = true
18
- insert_final_newline = true
19
-
20
- [*.md]
21
- trim_trailing_whitespace = false
22
-
23
- [*.json]
24
- indent_size = 2
25
-
26
- [*.{html,js,md}]
27
- block_comment_start = /**
28
- block_comment = *
29
- block_comment_end = */
@@ -1,22 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en-GB">
3
- <head>
4
- <meta charset="utf-8" />
5
- <style>
6
- body {
7
- background: #fafafa;
8
- }
9
- </style>
10
- </head>
11
- <body>
12
- <div id="demo"></div>
13
-
14
- <script type="module">
15
- import { html, render } from 'lit'
16
- import '../dist/src/property-angle.js'
17
- import '../dist/src/property-3dish.js'
18
-
19
- render(html` <property-3dish></property-3dish> `, document.querySelector('#demo'))
20
- </script>
21
- </body>
22
- </html>
@@ -1,31 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en-GB">
3
- <head>
4
- <meta charset="utf-8" />
5
- <style>
6
- body {
7
- background: #fafafa;
8
- }
9
- </style>
10
- </head>
11
- <body>
12
- <div id="demo"></div>
13
-
14
- <script type="module">
15
- import { html, render } from 'lit'
16
- import '../dist/src/property-angle.js'
17
-
18
- const placeholder = 'enter a angle in degree'
19
- render(
20
- html`
21
- <property-angle
22
- radian="1"
23
- placeholder=${placeholder}
24
- @change=${e => console.log(e.target.radian)}
25
- ></property-angle>
26
- `,
27
- document.querySelector('#demo')
28
- )
29
- </script>
30
- </body>
31
- </html>
@@ -1,30 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en-GB">
3
- <head>
4
- <meta charset="utf-8" />
5
- <style>
6
- body {
7
- background: #fafafa;
8
- }
9
- </style>
10
- </head>
11
- <body>
12
- <div id="demo"></div>
13
-
14
- <script type="module">
15
- import { html, render } from 'lit'
16
- import '../dist/src/property-buttons-radio.js'
17
-
18
- render(
19
- html`
20
- <property-buttons-radio @change=${e => console.log(e.target.value)}>
21
- <div data-value="top">TOP</div>
22
- <div data-value="middle">MID</div>
23
- <div data-value="bottom">BOT</div>
24
- </property-buttons-radio>
25
- `,
26
- document.querySelector('#demo')
27
- )
28
- </script>
29
- </body>
30
- </html>
@@ -1,30 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
- import { LitElement } from 'lit';
5
- export declare class Property3Dish extends LitElement {
6
- static styles: import("lit").CSSResult[];
7
- dimension?: {
8
- width: number;
9
- height: number;
10
- depth: number;
11
- };
12
- translatex?: {
13
- x: number;
14
- y: number;
15
- z: number;
16
- };
17
- rotate?: {
18
- x: number;
19
- y: number;
20
- z: number;
21
- };
22
- scale?: {
23
- x: number;
24
- y: number;
25
- z: number;
26
- };
27
- firstUpdated(): void;
28
- _onChange(e: Event): void;
29
- render(): import("lit-html").TemplateResult<1>;
30
- }