@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
@@ -1,150 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { LitElement, css, html } from 'lit'
6
- import { customElement, property } from 'lit/decorators.js'
7
-
8
- import { PropertyAngle } from './property-angle'
9
-
10
- @customElement('property-3dish')
11
- export class Property3Dish extends LitElement {
12
- static styles = [
13
- css`
14
- :host {
15
- display: grid;
16
- grid-template-columns: repeat(4, minmax(50px, 1fr));
17
- grid-gap: 5px;
18
- grid-auto-rows: minmax(24px, auto);
19
- }
20
-
21
- :host > * {
22
- grid-column: span 1;
23
- }
24
-
25
- label {
26
- text-align: right;
27
- }
28
-
29
- span {
30
- text-align: center;
31
- }
32
- `
33
- ]
34
-
35
- @property({ type: Object }) dimension?: { width: number; height: number; depth: number }
36
- /*
37
- * translate는 고유한 html element의 attribute이므로, property는 translatex로 한다.
38
- */
39
- @property({ type: Object }) translatex?: { x: number; y: number; z: number }
40
- @property({ type: Object }) rotate?: { x: number; y: number; z: number }
41
- @property({ type: Object }) scale?: { x: number; y: number; z: number }
42
-
43
- firstUpdated() {
44
- this.renderRoot.addEventListener('change', this._onChange.bind(this))
45
- }
46
-
47
- _onChange(e: Event) {
48
- var element = e.target as HTMLElement
49
- var id = element.id
50
- var prop = id.substr(1)
51
- var value = Number((element as HTMLInputElement).value)
52
-
53
- switch (element.tagName) {
54
- case 'PROPERTY-ANGLE':
55
- value = Number((element as PropertyAngle).radian || 0)
56
- break
57
- }
58
-
59
- switch (id) {
60
- case 'tx':
61
- case 'ty':
62
- case 'tz':
63
- this.dispatchEvent(
64
- new CustomEvent('translate-changed', {
65
- bubbles: true,
66
- composed: true,
67
- detail: {
68
- value: {
69
- ...this.translatex,
70
- [prop]: value
71
- }
72
- }
73
- })
74
- )
75
- break
76
-
77
- case 'rx':
78
- case 'ry':
79
- case 'rz':
80
- this.dispatchEvent(
81
- new CustomEvent('rotate-changed', {
82
- bubbles: true,
83
- composed: true,
84
- detail: {
85
- value: {
86
- ...this.rotate,
87
- [prop]: value
88
- }
89
- }
90
- })
91
- )
92
- break
93
-
94
- case 'sx':
95
- case 'sy':
96
- case 'sz':
97
- this.dispatchEvent(
98
- new CustomEvent('scale-changed', {
99
- bubbles: true,
100
- composed: true,
101
- detail: {
102
- value: {
103
- ...this.scale,
104
- [prop]: value
105
- }
106
- }
107
- })
108
- )
109
- break
110
-
111
- default:
112
- // dimension
113
- this.dispatchEvent(
114
- new CustomEvent('dimension-changed', {
115
- bubbles: true,
116
- composed: true,
117
- detail: {
118
- value: {
119
- ...this.dimension,
120
- [prop]: value
121
- }
122
- }
123
- })
124
- )
125
- }
126
- }
127
-
128
- render() {
129
- return html`
130
- <span></span> <span><i18n-msg msgid="label.x-axes">x-axes</i18n-msg></span>
131
- <span><i18n-msg msgid="label.y-axes">y-axes</i18n-msg></span>
132
- <span><i18n-msg msgid="label.z-axes">z-axes</i18n-msg></span>
133
-
134
- <label><i18n-msg msgid="label.dimension">dimension</i18n-msg></label>
135
- <input type="number" id="dwidth" .value=${this.dimension?.width} />
136
- <input type="number" id="dheight" .value=${this.dimension?.height} />
137
- <input type="number" id="ddepth" .value=${this.dimension?.depth} />
138
-
139
- <label><i18n-msg msgid="label.translate">translate</i18n-msg></label>
140
- <input type="number" id="tx" .value=${this.translatex?.x} />
141
- <input type="number" id="ty" .value=${this.translatex?.y} />
142
- <input type="number" id="tz" .value=${this.translatex?.z} />
143
-
144
- <label><i18n-msg msgid="label.rotate">rotate</i18n-msg></label>
145
- <property-angle id="rx" .radian=${this.rotate?.x}></property-angle>
146
- <property-angle id="ry" .radian=${this.rotate?.y}></property-angle>
147
- <property-angle id="rz" .radian=${this.rotate?.z}></property-angle>
148
- `
149
- }
150
- }
@@ -1,56 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { LitElement, css, html } from 'lit'
6
- import { customElement, property, query } from 'lit/decorators.js'
7
-
8
- @customElement('property-angle')
9
- export class PropertyAngle extends LitElement {
10
- static styles = [
11
- css`
12
- :host {
13
- display: inline-block;
14
- }
15
-
16
- input {
17
- width: 100%;
18
- height: 100%;
19
- box-sizing: border-box;
20
- border: 1px solid rgba(0, 0, 0, 0.2);
21
- }
22
- `
23
- ]
24
-
25
- @property({ type: Number }) radian?: string | number
26
- @query('input') input!: HTMLInputElement
27
-
28
- render() {
29
- return html`
30
- <input
31
- type="number"
32
- .value=${this._toDegree(this.radian)}
33
- @change=${(e: Event) => this._onChangeValue(e)}
34
- .placeholder=${this.placeholder}
35
- />
36
- `
37
- }
38
-
39
- get placeholder() {
40
- return this.getAttribute('placeholder') || '0°'
41
- }
42
-
43
- _onChangeValue(e: Event) {
44
- this.radian = this._toRadian(this.input.value)
45
-
46
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
47
- }
48
-
49
- _toDegree(radian: string | number | undefined) {
50
- return Math.round(((Number(radian) || 0) * 180) / Math.PI)
51
- }
52
-
53
- _toRadian(degree: string | number | undefined) {
54
- return isNaN(Number(degree)) ? undefined : Number(degree) * (Math.PI / 180)
55
- }
56
- }
@@ -1,87 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { LitElement, PropertyValues, css, html } from 'lit'
6
- import { customElement, property, query } from 'lit/decorators.js'
7
-
8
- /**
9
- 여러 버튼 중에서 하나만 눌리거나, 모두 눌리지 않은 상태만을 갖는 라디오 형태의 버튼이다.
10
-
11
- Example:
12
-
13
- <property-buttons-radio @change=${e => this._onChange(e)} value=${value}>
14
- <div data-value="top"></div>
15
- <div data-value="middle"></div>
16
- <div data-value="bottom"></div>
17
- </property-buttons-radio>
18
- */
19
- @customElement('property-buttons-radio')
20
- export class PropertyButtonsRadio extends LitElement {
21
- static styles = [
22
- css`
23
- :host {
24
- display: inline-block;
25
- }
26
- `
27
- ]
28
-
29
- /**
30
- * `value`는 버튼의 눌린 상태를 값으로 갖는 속성이다.
31
- */
32
- @property({ type: Object }) value: Object | null = null
33
- @property({ type: Boolean }) mandatory!: boolean
34
-
35
- render() {
36
- return html` <slot @click=${(e: Event) => this._onTapButton(e)}></slot> `
37
- }
38
-
39
- updated(changes: PropertyValues<this>) {
40
- changes.has('value') && this._onValueChanged(this.value)
41
- }
42
-
43
- get buttons() {
44
- return Array.from(this.querySelectorAll('*'))
45
- }
46
-
47
- _onValueChanged(value: Object | null) {
48
- this.buttons.forEach(button => {
49
- if (value === button.getAttribute('data-value')) {
50
- button.setAttribute('active', '')
51
- } else {
52
- button.removeAttribute('active')
53
- }
54
- })
55
- }
56
-
57
- _onTapButton(e: Event) {
58
- var target = e.target as HTMLElement
59
-
60
- while (!target.hasAttribute('data-value') && target !== this) {
61
- target = target.parentElement!
62
- }
63
-
64
- if (target === this) {
65
- return
66
- }
67
-
68
- var old = this.value
69
-
70
- if (!this.mandatory) {
71
- if (!target.getAttribute('active')) {
72
- this.value = target.getAttribute('data-value')
73
- target.setAttribute('active', '')
74
- } else {
75
- this.value = null
76
- target.removeAttribute('active')
77
- }
78
- } else {
79
- this.value = target.getAttribute('data-value')
80
- target.setAttribute('active', '')
81
- }
82
-
83
- if (old !== this.value) {
84
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
85
- }
86
- }
87
- }
@@ -1,109 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { LitElement, css, html } from 'lit'
6
- import { customElement, property } from 'lit/decorators.js'
7
-
8
- @customElement('property-stack')
9
- export default class PropertyStack extends LitElement {
10
- static styles = [
11
- css`
12
- :host {
13
- display: block;
14
- }
15
-
16
- #add-floor {
17
- width: 100%;
18
- height: 20px;
19
- background-color: blue;
20
- color: white;
21
- }
22
-
23
- div {
24
- background-color: blue;
25
- width: calc(100% - 40px);
26
- width: -webkit-calc(100% - 40px);
27
- min-height: 20px;
28
- }
29
-
30
- div[active] {
31
- background-color: red;
32
- }
33
-
34
- div button {
35
- position: absolute;
36
- right: 10px;
37
- width: 30px;
38
- min-height: 20px;
39
- }
40
- `
41
- ]
42
-
43
- /**
44
- * `stack`은 stack에 의해 만들어진 층의 배열을 유지한다.
45
- */
46
- @property({ type: Array }) stack: { name: string }[] = []
47
-
48
- /**
49
- * `activeIndex`은 현재 active된 층의 인덱스를 유지한다.
50
- */
51
- @property({ type: Number }) activeIndex: number = 0
52
-
53
- render() {
54
- const stack = [...this.stack].reverse()
55
- const length = stack.length
56
-
57
- return html`
58
- <button id="add-floor" @click=${(e: Event) => this._onClickAddFloor(e)}>+</button>
59
-
60
- ${stack.map(
61
- (item, index) => html`
62
- <div
63
- ?active=${length - index - 1 == this.activeIndex}
64
- @click=${(e: Event) => this._onClickToActive(e)}
65
- idx=${length - index - 1}
66
- >
67
- ${item.name} <button @click=${(e: Event) => this._onClickRemoveFloor(e)}>-</button>
68
- </div>
69
- `
70
- )}
71
- `
72
- }
73
-
74
- _onClickAddFloor(e: Event) {
75
- this.stack.push({ name: String(this.stack.length + 1) })
76
- this.requestUpdate()
77
- }
78
-
79
- _onClickToActive(e: Event) {
80
- const div = e.target as HTMLElement
81
- if (div.tagName != 'DIV') {
82
- return
83
- }
84
-
85
- this.activeIndex = Number(div.getAttribute('idx'))
86
- }
87
-
88
- _onClickRemoveFloor(e: Event) {
89
- const div = (e.target as HTMLElement).parentElement
90
-
91
- if (div?.tagName != 'DIV') {
92
- return
93
- }
94
-
95
- const idx = Number(div.getAttribute('idx'))
96
-
97
- this.stack.splice(idx, 1)
98
-
99
- if (this.activeIndex == idx) {
100
- this.activeIndex = 0
101
- } else if (this.activeIndex >= idx) {
102
- this.activeIndex--
103
- } else if (this.activeIndex >= this.stack.length) {
104
- this.activeIndex = 0
105
- }
106
-
107
- this.requestUpdate()
108
- }
109
- }
@@ -1,32 +0,0 @@
1
- import { expect, fixture } from '@open-wc/testing'
2
-
3
- import { PropertyAngle } from '../src/property-angle'
4
- import { html } from 'lit'
5
-
6
- describe('PropertyAngle', () => {
7
- it('has a default title "Hey there" and angle 5', async () => {
8
- const el = await fixture<PropertyAngle>(html`<property-angle></property-angle>`)
9
-
10
- expect(el.title).to.equal('Hey there')
11
- expect(el.radian).to.equal(5)
12
- })
13
-
14
- it('increases the angle on button click', async () => {
15
- const el = await fixture<PropertyAngle>(html`<property-angle></property-angle>`)
16
- el.shadowRoot!.querySelector('button')!.click()
17
-
18
- expect(el.radian).to.equal(6)
19
- })
20
-
21
- it('can override the title via attribute', async () => {
22
- const el = await fixture<PropertyAngle>(html`<property-angle title="attribute title"></property-angle>`)
23
-
24
- expect(el.title).to.equal('attribute title')
25
- })
26
-
27
- it('passes the a11y audit', async () => {
28
- const el = await fixture<PropertyAngle>(html`<property-angle></property-angle>`)
29
-
30
- await expect(el).shadowDom.to.be.accessible()
31
- })
32
- })