@operato/form 8.0.0-alpha.6 → 8.0.0-beta.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +156 -0
  2. package/dist/src/filters/ox-filters-form-base.js +2 -1
  3. package/dist/src/filters/ox-filters-form-base.js.map +1 -1
  4. package/dist/tsconfig.tsbuildinfo +1 -1
  5. package/package.json +15 -15
  6. package/themes/calendar-theme.css +3 -1
  7. package/.editorconfig +0 -29
  8. package/.storybook/main.js +0 -3
  9. package/.storybook/preview.js +0 -52
  10. package/.storybook/server.mjs +0 -8
  11. package/src/components/ox-custom-input.ts +0 -102
  12. package/src/components/ox-custom-select.ts +0 -91
  13. package/src/components/ox-file-uploader.ts +0 -164
  14. package/src/components/ox-form-master.ts +0 -246
  15. package/src/components/ox-form-paginator.ts +0 -60
  16. package/src/components/ox-search-form-paginator.ts +0 -46
  17. package/src/components/ox-search-form.ts +0 -467
  18. package/src/filters/filter-checkbox.ts +0 -34
  19. package/src/filters/filter-input-barcode.ts +0 -35
  20. package/src/filters/filter-input.ts +0 -30
  21. package/src/filters/filter-range-date.ts +0 -81
  22. package/src/filters/filter-range-number.ts +0 -64
  23. package/src/filters/filter-select.ts +0 -56
  24. package/src/filters/filter-styles.ts +0 -127
  25. package/src/filters/index.ts +0 -10
  26. package/src/filters/ox-filter-personalizer.ts +0 -188
  27. package/src/filters/ox-filters-form-base.ts +0 -436
  28. package/src/filters/registry.ts +0 -54
  29. package/src/index.ts +0 -4
  30. package/src/styles/index.ts +0 -3
  31. package/src/styles/multi-column-form-styles.ts +0 -192
  32. package/src/styles/search-form-styles.ts +0 -160
  33. package/src/styles/single-column-form-styles.ts +0 -114
  34. package/src/types.ts +0 -106
  35. package/stories/ox-filters-form-barcode.stories.ts +0 -140
  36. package/stories/ox-filters-form-base-bounded.stories.ts +0 -208
  37. package/stories/ox-filters-form-base-change-handler.stories.ts +0 -220
  38. package/stories/ox-filters-form-base-page-preference.stories.ts +0 -177
  39. package/stories/ox-filters-form-base.stories.ts +0 -179
  40. package/stories/ox-search-form-change-handler.stories.ts +0 -253
  41. package/stories/ox-search-form.stories.ts +0 -258
  42. package/tsconfig.json +0 -24
  43. package/web-dev-server.config.mjs +0 -27
  44. package/web-test-runner.config.mjs +0 -41
@@ -1,246 +0,0 @@
1
- import { LitElement, PropertyValues, css, html } from 'lit'
2
- import { customElement, property, query, state } from 'lit/decorators.js'
3
-
4
- import { CustomInput } from './ox-custom-input.js'
5
- import { CustomSelect } from './ox-custom-select.js'
6
- import { FormPaginator } from './ox-form-paginator.js'
7
-
8
- @customElement('ox-form-master')
9
- class FormMaster extends LitElement {
10
- static styles = css`
11
- form {
12
- display: grid;
13
- padding: var(--form-padding, 10px);
14
- grid-gap: var(--form-grid-gap, 10px);
15
- grid-template-columns: var(--form-grid-template-columns);
16
- background-color: var(--form-background-color, #e5e5e5);
17
- }
18
- custom-input,
19
- custom-select {
20
- justify-self: center;
21
- }
22
- `
23
-
24
- @property({ type: Array }) fields?: {
25
- type: string
26
- hidden: boolean
27
- name: string
28
- id: string
29
- label: string
30
- placeholder: string
31
- value: any
32
- field: string
33
- queryName: string
34
- props: { [prop: string]: string }
35
- attrs: string[]
36
- valueField?: string
37
- displayField?: string
38
- options: { name: string; value: string }[]
39
- }[]
40
- @property({ type: Number }) maxRowCount: number = 2
41
- @property({ type: Number }) maxColumnCount: number = 4
42
- @property({ type: String }) initFocus?: string
43
-
44
- @state() private pageCount!: number
45
-
46
- @query('form') form!: HTMLFormElement
47
-
48
- private loadedCount: number = 0
49
- private resizeEventHandler?: EventListener
50
-
51
- connectedCallback(): void {
52
- super.connectedCallback()
53
-
54
- this.resizeEventHandler = this._adjustColumnProperty.bind(this)
55
- window.addEventListener('resize', this.resizeEventHandler)
56
- }
57
-
58
- disconnectedCallback(): void {
59
- super.disconnectedCallback()
60
-
61
- if (this.resizeEventHandler) {
62
- window.removeEventListener('resize', this.resizeEventHandler)
63
- }
64
- }
65
-
66
- render() {
67
- return html`
68
- <form
69
- @keypress=${(e: KeyboardEvent) => {
70
- if (e.key === 'Enter') {
71
- this.submit()
72
- }
73
- }}
74
- @submit=${(e: Event) => {
75
- e.preventDefault() // input="text" 가 한개만 있을경우에 엔터를 치면 강제 submit되는 증상 방지
76
- }}
77
- >
78
- ${(this.fields || []).map(
79
- field => html`
80
- ${field.type === 'select'
81
- ? html`
82
- <ox-custom-select
83
- id=${field.id || field.name}
84
- name=${field.name || field.id}
85
- .props=${field.props}
86
- .attrs=${field.attrs}
87
- .value=${field.value}
88
- .autofocus=${this.initFocus === field.name}
89
- placeholder=${field.placeholder}
90
- @load=${this._onInputLoad.bind(this)}
91
- .options=${field.options}
92
- ></ox-custom-select>
93
- `
94
- : html`
95
- <ox-custom-input
96
- id=${field.id || field.name}
97
- name=${field.name || field.id}
98
- .props=${field.props}
99
- .attrs=${field.attrs}
100
- .valueField=${field.valueField}
101
- .displayField=${field.displayField}
102
- .value=${field.value}
103
- .autofocus=${this.initFocus === field.name}
104
- placeholder=${field.placeholder}
105
- @load=${this._onInputLoad.bind(this)}
106
- ></ox-custom-input>
107
- `}
108
- `
109
- )}
110
- </form>
111
-
112
- <form-paginator .pageCount=${this.pageCount} @pageChange=${this._onPageChangeHandler.bind(this)}></form-paginator>
113
- `
114
- }
115
-
116
- updated(changes: PropertyValues<this>) {
117
- if (changes.has('fields')) {
118
- this._checkInputValidity()
119
- }
120
- }
121
-
122
- _checkInputValidity() {
123
- const names = (this.fields || []).map(i => i.name)
124
- const result = names.every(name => {
125
- return names.indexOf(name) === names.lastIndexOf(name)
126
- })
127
- if (!result) {
128
- throw new Error('Field name is duplicated.')
129
- }
130
- }
131
-
132
- _onInputLoad() {
133
- this.loadedCount++
134
- if (this.loadedCount === (this.fields || []).length - 1) {
135
- this._adjustColumnProperty()
136
- this._initFocus()
137
- this.dispatchEvent(new CustomEvent('load'))
138
- }
139
- }
140
-
141
- getFields(): (CustomInput | CustomSelect)[] {
142
- return Array.from(this.form.querySelectorAll('ox-custom-select, ox-custom-input') || [])
143
- }
144
-
145
- private currentPage: number = 1
146
-
147
- _adjustColumnProperty() {
148
- const inputElements = this.getFields()
149
-
150
- if (inputElements.length === 0) return
151
- const inputWidth = inputElements[0].offsetWidth
152
- const totalWidth = window.innerWidth
153
- const inputCount = inputElements.length
154
- let columnCount =
155
- Math.floor(totalWidth / inputWidth) < this.maxColumnCount
156
- ? Math.floor(totalWidth / inputWidth)
157
- : this.maxColumnCount > inputCount
158
- ? inputCount
159
- : this.maxColumnCount
160
-
161
- if (columnCount === 1) {
162
- this.pageCount = Math.ceil(inputElements.length / this.maxRowCount)
163
- this._filterActiveFields(this.currentPage)
164
- } else {
165
- this.pageCount = 1
166
- this._activeFields()
167
- }
168
-
169
- this.style.setProperty('--form-grid-template-columns', `repeat(${columnCount}, 1fr)`)
170
- }
171
-
172
- _initFocus() {
173
- if (!this.initFocus) this.getFields()[0].focus()
174
- }
175
-
176
- getFieldByName(name: string) {
177
- return this.renderRoot.querySelector(`[name=${name}]`)
178
- }
179
-
180
- reset() {
181
- this.form && this.form.reset()
182
- }
183
-
184
- submit() {
185
- this.dispatchEvent(new CustomEvent('submit'))
186
- }
187
-
188
- focusById(id: string) {
189
- const input = this.renderRoot.querySelector(`form > #${id}`) as CustomInput | CustomSelect
190
- input.focus()
191
- }
192
-
193
- checkValidity() {
194
- return this.form.checkValidity()
195
- }
196
-
197
- serialize() {
198
- let data: { [name: string]: any } = {}
199
-
200
- this.getFields().forEach(field => {
201
- const name = field.name
202
- if (name) {
203
- data[name] = field.value
204
- }
205
- })
206
-
207
- return data
208
- }
209
-
210
- get searchParams() {
211
- let searchParam = new URLSearchParams()
212
- const data = this.serialize()
213
- const fields = this.getFields()
214
- fields.forEach(field => searchParam.append(field.name!, field.value))
215
-
216
- return decodeURI(searchParam.toString())
217
- }
218
-
219
- _onPageChangeHandler(event: Event) {
220
- this.currentPage = (event.currentTarget as FormPaginator).currentPage
221
- this._filterActiveFields(this.currentPage)
222
- }
223
-
224
- _activeFields() {
225
- this.getFields().forEach(field => (field.hidden = false))
226
- }
227
-
228
- _filterActiveFields(currentPage = 1) {
229
- if (this.pageCount > 1) {
230
- const fields = this.getFields()
231
-
232
- const chunkedFields = []
233
- for (let i = 0, j = fields.length; i < j; i += this.maxRowCount) {
234
- chunkedFields.push(fields.slice(i, i + this.maxRowCount))
235
- }
236
-
237
- chunkedFields.forEach((fields, idx) => {
238
- if (currentPage === idx + 1) {
239
- fields.forEach(field => (field.hidden = false))
240
- } else {
241
- fields.forEach(field => (field.hidden = true))
242
- }
243
- })
244
- }
245
- }
246
- }
@@ -1,60 +0,0 @@
1
- import { LitElement, PropertyValues, css, html } from 'lit'
2
- import { customElement, property, state } from 'lit/decorators.js'
3
-
4
- @customElement('form-paginator')
5
- export class FormPaginator extends LitElement {
6
- static styles = css`
7
- :host {
8
- display: block;
9
- background-color: var(--form-background-color, #e5e5e5);
10
- font-size: 1.5em;
11
- line-height: 0.5em;
12
- text-align: center;
13
- color: #c4c5c6;
14
- }
15
-
16
- [selected] {
17
- color: #6f6f6f;
18
- }
19
- `
20
-
21
- @property({ type: Number }) pageCount: number = 1
22
- @property({ type: Array }) selectors: number[] = []
23
-
24
- @state() public currentPage: number = 1
25
-
26
- render() {
27
- return html`
28
- ${this.selectors.map(
29
- page => html`
30
- <span
31
- page=${page}
32
- ?selected=${page == this.currentPage}
33
- @click=${(e: MouseEvent) => {
34
- this.currentPage = page
35
- this.dispatchEvent(new CustomEvent('pageChange'))
36
- this.requestUpdate()
37
- }}
38
- >&bull;</span
39
- >
40
- `
41
- )}
42
- `
43
- }
44
-
45
- updated(changes: PropertyValues<this>) {
46
- if (changes.has('pageCount')) {
47
- if (this.pageCount > 1) {
48
- let i = 1
49
- this.selectors = []
50
-
51
- while (i <= this.pageCount) {
52
- this.selectors.push(i)
53
- i++
54
- }
55
- } else {
56
- this.selectors = []
57
- }
58
- }
59
- }
60
- }
@@ -1,46 +0,0 @@
1
- import { LitElement, css, html } from 'lit'
2
- import { customElement, property } from 'lit/decorators.js'
3
-
4
- @customElement('ox-search-form-paginator')
5
- class SearchFormPaginator extends LitElement {
6
- static styles = css`
7
- :host {
8
- display: block;
9
- background-color: var(--form-background-color, #e5e5e5);
10
- font-size: 1.5em;
11
- line-height: 0.5em;
12
- text-align: center;
13
- color: #c4c5c6;
14
- }
15
-
16
- [selected] {
17
- color: #6f6f6f;
18
- }
19
- `
20
-
21
- @property({ type: Number }) pageCount: number = 0
22
- @property({ type: Number }) currentPage: number = 0
23
-
24
- render() {
25
- return html`
26
- ${Array(this.pageCount)
27
- .fill('')
28
- .map(
29
- (_, page) => html`
30
- <span
31
- ?selected=${page == this.currentPage}
32
- @click=${(e: MouseEvent) =>
33
- this.dispatchEvent(
34
- new CustomEvent('pagechanged', {
35
- detail: {
36
- page
37
- }
38
- })
39
- )}
40
- >&bull;</span
41
- >
42
- `
43
- )}
44
- `
45
- }
46
- }