@things-factory/biz-base 10.1.278 → 10.1.279
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/package.json +18 -4
- package/.yo-rc.json +0 -7
- package/CHANGELOG.md +0 -14
- package/client/counterparty-register-form.ts +0 -213
- package/client/counterparty-register.ts +0 -52
- package/client/counterparty-select.ts +0 -221
- package/client/index.ts +0 -9
- package/dist-client/counterparty-register-form.js.map +0 -1
- package/dist-client/counterparty-register.js.map +0 -1
- package/dist-client/counterparty-select.js.map +0 -1
- package/dist-client/index.js.map +0 -1
- package/dist-client/tsconfig.tsbuildinfo +0 -1
- package/dist-server/index.js.map +0 -1
- package/dist-server/middlewares/index.js.map +0 -1
- package/dist-server/migrations/index.js.map +0 -1
- package/dist-server/role-tasks.js.map +0 -1
- package/dist-server/service/biz-option/biz-option-mutation.js.map +0 -1
- package/dist-server/service/biz-option/biz-option-query.js.map +0 -1
- package/dist-server/service/biz-option/biz-option-types.js.map +0 -1
- package/dist-server/service/biz-option/biz-option.js.map +0 -1
- package/dist-server/service/biz-option/index.js.map +0 -1
- package/dist-server/service/biz-option-detail/biz-option-detail-mutation.js.map +0 -1
- package/dist-server/service/biz-option-detail/biz-option-detail-query.js.map +0 -1
- package/dist-server/service/biz-option-detail/biz-option-detail-types.js.map +0 -1
- package/dist-server/service/biz-option-detail/biz-option-detail.js.map +0 -1
- package/dist-server/service/biz-option-detail/index.js.map +0 -1
- package/dist-server/service/bizplace/bizplace-access.js.map +0 -1
- package/dist-server/service/bizplace/bizplace-mutation.js.map +0 -1
- package/dist-server/service/bizplace/bizplace-query.js.map +0 -1
- package/dist-server/service/bizplace/bizplace-types.js.map +0 -1
- package/dist-server/service/bizplace/bizplace.js.map +0 -1
- package/dist-server/service/bizplace/index.js.map +0 -1
- package/dist-server/service/company/company-mutation.js.map +0 -1
- package/dist-server/service/company/company-query.js.map +0 -1
- package/dist-server/service/company/company-types.js.map +0 -1
- package/dist-server/service/company/company.js.map +0 -1
- package/dist-server/service/company/index.js.map +0 -1
- package/dist-server/service/company/our-company.js.map +0 -1
- package/dist-server/service/company-seal/company-seal-mutation.js.map +0 -1
- package/dist-server/service/company-seal/company-seal-query.js.map +0 -1
- package/dist-server/service/company-seal/company-seal-reader.js.map +0 -1
- package/dist-server/service/company-seal/company-seal-rules.js.map +0 -1
- package/dist-server/service/company-seal/company-seal-service.js.map +0 -1
- package/dist-server/service/company-seal/company-seal-types.js.map +0 -1
- package/dist-server/service/company-seal/company-seal.js.map +0 -1
- package/dist-server/service/company-seal/index.js.map +0 -1
- package/dist-server/service/counterparty/counterparty-bank-account-mutation.js.map +0 -1
- package/dist-server/service/counterparty/counterparty-bank-account-query.js.map +0 -1
- package/dist-server/service/counterparty/counterparty-bank-account-service.js.map +0 -1
- package/dist-server/service/counterparty/counterparty-bank-account.js.map +0 -1
- package/dist-server/service/counterparty/counterparty-choice.js.map +0 -1
- package/dist-server/service/counterparty/counterparty-document-readers.js.map +0 -1
- package/dist-server/service/counterparty/counterparty-mutation.js.map +0 -1
- package/dist-server/service/counterparty/counterparty-names.js.map +0 -1
- package/dist-server/service/counterparty/counterparty-query.js.map +0 -1
- package/dist-server/service/counterparty/counterparty-service.js.map +0 -1
- package/dist-server/service/counterparty/counterparty-type.js.map +0 -1
- package/dist-server/service/counterparty/counterparty.js.map +0 -1
- package/dist-server/service/counterparty/index.js.map +0 -1
- package/dist-server/service/index.js.map +0 -1
- package/dist-server/service/worker/index.js.map +0 -1
- package/dist-server/service/worker/worker-mutation.js.map +0 -1
- package/dist-server/service/worker/worker-query.js.map +0 -1
- package/dist-server/service/worker/worker-types.js.map +0 -1
- package/dist-server/service/worker/worker.js.map +0 -1
- package/dist-server/tsconfig.tsbuildinfo +0 -1
- package/dist-server/utils/get-permitted-bizplaces.js.map +0 -1
- package/dist-server/utils/index.js.map +0 -1
- package/dist-server/work-doors.js.map +0 -1
- package/note +0 -41
- package/tests/bizplace-access.test.cjs +0 -181
- package/tests/company-seal.test.mjs +0 -103
- package/tests/counterparty-bank-account.test.mjs +0 -125
- package/tests/counterparty-names.test.mjs +0 -154
- package/tests/counterparty-published.test.mjs +0 -105
- package/tests/counterparty-register.test.mjs +0 -40
- package/tests/counterparty.test.mjs +0 -121
- package/tests/doors.test.mjs +0 -32
- package/tests/our-company.test.mjs +0 -72
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/biz-base",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.279",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "dist-client/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -11,6 +11,20 @@
|
|
|
11
11
|
"./counterparty-names": "./dist-server/service/counterparty/counterparty-names.js",
|
|
12
12
|
"./*": "./*"
|
|
13
13
|
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist-client",
|
|
16
|
+
"dist-server",
|
|
17
|
+
"things-factory.config.js",
|
|
18
|
+
"translations",
|
|
19
|
+
"!**/*.map",
|
|
20
|
+
"!**/*.test.*",
|
|
21
|
+
"!**/*.spec.*",
|
|
22
|
+
"!**/test/**",
|
|
23
|
+
"!**/tests/**",
|
|
24
|
+
"!**/__tests__/**",
|
|
25
|
+
"!**/*.tsbuildinfo",
|
|
26
|
+
"!**/.DS_Store"
|
|
27
|
+
],
|
|
14
28
|
"typesVersions": {
|
|
15
29
|
"*": {
|
|
16
30
|
"counterparty-names": [
|
|
@@ -50,8 +64,8 @@
|
|
|
50
64
|
"@operato/layout": "^10.29.69",
|
|
51
65
|
"@operato/popup": "^10.0.0",
|
|
52
66
|
"@operato/styles": "^10.29.1",
|
|
53
|
-
"@things-factory/attachment-base": "^10.1.
|
|
54
|
-
"@things-factory/auth-base": "^10.1.
|
|
67
|
+
"@things-factory/attachment-base": "^10.1.279",
|
|
68
|
+
"@things-factory/auth-base": "^10.1.279"
|
|
55
69
|
},
|
|
56
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "666c08055c408b408fde961ad10da080941b147c"
|
|
57
71
|
}
|
package/.yo-rc.json
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
|
|
5
|
-
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
6
|
-
and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
7
|
-
|
|
8
|
-
<!-- ## [Unreleased] -->
|
|
9
|
-
|
|
10
|
-
### Fixed
|
|
11
|
-
|
|
12
|
-
- Enforce domain ownership for bizplace mutations and constrain reads to existing permitted and partner scopes.
|
|
13
|
-
- Reject caller-supplied IDs on bulk creation and roll back mixed-domain bulk mutations.
|
|
14
|
-
- Prevent primary-key changes and unauthorized company references in bizplace patches.
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import '@material/web/button/filled-button.js'
|
|
2
|
-
import '@material/web/button/text-button.js'
|
|
3
|
-
import '@operato/input/ox-input-select-buttons.js'
|
|
4
|
-
import '@operato/popup/ox-popup-actions.js'
|
|
5
|
-
|
|
6
|
-
import gql from 'graphql-tag'
|
|
7
|
-
import { css, html, LitElement, nothing } from 'lit'
|
|
8
|
-
import { customElement, property, state } from 'lit/decorators.js'
|
|
9
|
-
|
|
10
|
-
import { gqlContext, MutationController, QueryController } from '@operato/graphql'
|
|
11
|
-
import { i18next, localize } from '@operato/i18n'
|
|
12
|
-
import { CommonPopupStyles, FormFieldStyles, PopupBodyStyles, PopupFieldStyles } from '@operato/styles'
|
|
13
|
-
|
|
14
|
-
/** The kinds a counterparty registered here may be - our own company is one per domain and kept on its own screen. */
|
|
15
|
-
const KINDS = ['COMPANY', 'INSTITUTION', 'PERSON']
|
|
16
|
-
|
|
17
|
-
const SAME_NAMED = gql`
|
|
18
|
-
query ($name: String!) {
|
|
19
|
-
counterpartiesNamed(name: $name) {
|
|
20
|
-
id
|
|
21
|
-
name
|
|
22
|
-
kind
|
|
23
|
-
businessNumber
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
`
|
|
27
|
-
|
|
28
|
-
const REGISTER = gql`
|
|
29
|
-
mutation ($counterparty: NewCounterparty!) {
|
|
30
|
-
createCounterparty(counterparty: $counterparty) {
|
|
31
|
-
id
|
|
32
|
-
name
|
|
33
|
-
kind
|
|
34
|
-
businessNumber
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
`
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Create a counterparty from the picker through createCounterparty. Collect name, kind and known
|
|
41
|
-
* registration details; emit counterparty on selection and close on cancellation. For a normalized existing
|
|
42
|
-
* name or alias, offer the existing record instead of creating a duplicate (ADR-0195).
|
|
43
|
-
*/
|
|
44
|
-
@customElement('counterparty-register-form')
|
|
45
|
-
export class CounterpartyRegisterForm extends localize(i18next)(LitElement) {
|
|
46
|
-
/* The shared popup layout (page-standard sections 7, 8): only the body scrolls, labels above native inputs. */
|
|
47
|
-
static styles = [
|
|
48
|
-
CommonPopupStyles,
|
|
49
|
-
PopupBodyStyles,
|
|
50
|
-
FormFieldStyles,
|
|
51
|
-
PopupFieldStyles,
|
|
52
|
-
css`
|
|
53
|
-
ox-input-select-buttons {
|
|
54
|
-
align-self: flex-start;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
[guide] {
|
|
58
|
-
margin: 0;
|
|
59
|
-
color: var(--ui-muted);
|
|
60
|
-
line-height: var(--popup-line-height);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
[invalid] {
|
|
64
|
-
color: var(--ui-crit, var(--md-sys-color-error));
|
|
65
|
-
font-size: var(--ui-t-small, 11.5px);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
[invalid]:empty {
|
|
69
|
-
display: none;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
ul[same] {
|
|
73
|
-
list-style: none;
|
|
74
|
-
margin: 0;
|
|
75
|
-
padding: 0;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
ul[same] li {
|
|
79
|
-
display: flex;
|
|
80
|
-
align-items: center;
|
|
81
|
-
justify-content: space-between;
|
|
82
|
-
gap: var(--spacing-medium, 8px);
|
|
83
|
-
padding: 3px 0;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
ul[same] small {
|
|
87
|
-
color: var(--ui-muted);
|
|
88
|
-
}
|
|
89
|
-
`
|
|
90
|
-
]
|
|
91
|
-
|
|
92
|
-
/** The name the picker was searched by - the form starts from it. */
|
|
93
|
-
@property({ type: String }) name = ''
|
|
94
|
-
|
|
95
|
-
@state() private kind = 'COMPANY'
|
|
96
|
-
@state() private businessNumber = ''
|
|
97
|
-
@state() private representative = ''
|
|
98
|
-
/** The name asked about - set once the person stops typing. */
|
|
99
|
-
@state() private asked = ''
|
|
100
|
-
|
|
101
|
-
private timer?: ReturnType<typeof setTimeout>
|
|
102
|
-
|
|
103
|
-
private sameNamed = new QueryController(this, SAME_NAMED, {
|
|
104
|
-
variables: () => (this.asked ? { name: this.asked } : undefined),
|
|
105
|
-
fetchPolicy: 'no-cache',
|
|
106
|
-
context: gqlContext()
|
|
107
|
-
} as any)
|
|
108
|
-
|
|
109
|
-
private save = new MutationController(this, REGISTER, { context: gqlContext(), showsError: true } as any)
|
|
110
|
-
|
|
111
|
-
connectedCallback() {
|
|
112
|
-
super.connectedCallback()
|
|
113
|
-
this.asked = this.name.trim()
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** What the name check says for the name now in the field. */
|
|
117
|
-
private get check(): 'idle' | 'checking' | 'free' | 'taken' | 'failed' {
|
|
118
|
-
const name = this.name.trim()
|
|
119
|
-
if (!name || this.asked !== name) return 'idle'
|
|
120
|
-
if (this.sameNamed.loading) return 'checking'
|
|
121
|
-
const found = this.sameNamed.error ? undefined : this.sameNamed.data?.counterpartiesNamed
|
|
122
|
-
if (!Array.isArray(found)) return 'failed'
|
|
123
|
-
return found.length ? 'taken' : 'free'
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
private get registrable(): boolean {
|
|
127
|
-
return this.check === 'free' && !this.save.pending
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
render() {
|
|
131
|
-
const check = this.check
|
|
132
|
-
return html`
|
|
133
|
-
<div class="body">
|
|
134
|
-
<p guide>${i18next.t('text.counterparty-register-guide')}</p>
|
|
135
|
-
|
|
136
|
-
<label class="field">
|
|
137
|
-
<span>${i18next.t('field.counterparty-name')}</span>
|
|
138
|
-
<input name="name" .value=${this.name} @input=${(e: Event) => this.onName((e.target as HTMLInputElement).value)} />
|
|
139
|
-
<span invalid
|
|
140
|
-
>${check === 'failed' ? i18next.t('text.counterparty-name-check-failed') : check === 'checking' ? i18next.t('text.counterparty-checking-name') : ''}</span
|
|
141
|
-
>
|
|
142
|
-
</label>
|
|
143
|
-
|
|
144
|
-
${check === 'taken' ? this.renderSameNamed() : nothing}
|
|
145
|
-
|
|
146
|
-
<div class="field">
|
|
147
|
-
<span>${i18next.t('field.counterparty-kind')}</span>
|
|
148
|
-
<ox-input-select-buttons
|
|
149
|
-
.value=${this.kind}
|
|
150
|
-
.options=${KINDS.map(kind => ({ display: i18next.t(`text.counterparty-kind-${kind.toLowerCase()}`), value: kind }))}
|
|
151
|
-
@change=${(e: CustomEvent) => e.detail && (this.kind = e.detail)}
|
|
152
|
-
></ox-input-select-buttons>
|
|
153
|
-
</div>
|
|
154
|
-
|
|
155
|
-
<label class="field">
|
|
156
|
-
<span>${i18next.t('field.business-number')}</span>
|
|
157
|
-
<input name="businessNumber" .value=${this.businessNumber} inputmode="numeric" @input=${(e: Event) => (this.businessNumber = (e.target as HTMLInputElement).value)} />
|
|
158
|
-
<span>${i18next.t('text.business-number-hint')}</span>
|
|
159
|
-
</label>
|
|
160
|
-
|
|
161
|
-
<label class="field">
|
|
162
|
-
<span>${i18next.t('field.representative')}</span>
|
|
163
|
-
<input name="representative" .value=${this.representative} @input=${(e: Event) => (this.representative = (e.target as HTMLInputElement).value)} />
|
|
164
|
-
</label>
|
|
165
|
-
</div>
|
|
166
|
-
|
|
167
|
-
<ox-popup-actions>
|
|
168
|
-
<md-text-button slot="cancel" @click=${() => this.dispatchEvent(new CustomEvent('close'))}>${i18next.t('button.cancel')}</md-text-button>
|
|
169
|
-
<md-filled-button slot="confirm" ?disabled=${!this.registrable} @click=${() => this.register()}>${i18next.t('button.counterparty-register')}</md-filled-button>
|
|
170
|
-
</ox-popup-actions>
|
|
171
|
-
`
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
private renderSameNamed() {
|
|
175
|
-
const found: any[] = this.sameNamed.data?.counterpartiesNamed ?? []
|
|
176
|
-
return html`
|
|
177
|
-
<div class="field">
|
|
178
|
-
<span invalid>${i18next.t('text.counterparty-same-named')}</span>
|
|
179
|
-
<ul same>
|
|
180
|
-
${found.map(
|
|
181
|
-
one => html`<li>
|
|
182
|
-
<span>${one.name} ${one.businessNumber ? html`<small>${one.businessNumber}</small>` : nothing}</span>
|
|
183
|
-
<md-text-button @click=${() => this.take(one)}>${i18next.t('button.counterparty-choose-this')}</md-text-button>
|
|
184
|
-
</li>`
|
|
185
|
-
)}
|
|
186
|
-
</ul>
|
|
187
|
-
</div>
|
|
188
|
-
`
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private onName(value: string) {
|
|
192
|
-
this.name = value
|
|
193
|
-
clearTimeout(this.timer)
|
|
194
|
-
this.timer = setTimeout(() => (this.asked = this.name.trim()), 300)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
private async register() {
|
|
198
|
-
if (!this.registrable) return
|
|
199
|
-
const counterparty = {
|
|
200
|
-
name: this.name.trim(),
|
|
201
|
-
kind: this.kind,
|
|
202
|
-
...(this.businessNumber.trim() ? { businessNumber: this.businessNumber.trim() } : {}),
|
|
203
|
-
...(this.representative.trim() ? { representative: this.representative.trim() } : {})
|
|
204
|
-
}
|
|
205
|
-
const data: any = await this.save.run({ counterparty })
|
|
206
|
-
const saved = data?.createCounterparty
|
|
207
|
-
if (saved) this.take(saved)
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
private take(one: { id: string; name: string; businessNumber?: string | null; kind?: string | null }) {
|
|
211
|
-
this.dispatchEvent(new CustomEvent('counterparty', { detail: { id: one.id, name: one.name, businessNumber: one.businessNumber ?? null, kind: one.kind ?? null } }))
|
|
212
|
-
}
|
|
213
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import './counterparty-register-form.js'
|
|
2
|
-
|
|
3
|
-
import { html } from 'lit'
|
|
4
|
-
|
|
5
|
-
import { i18next } from '@operato/i18n'
|
|
6
|
-
import { openPopup } from '@operato/layout'
|
|
7
|
-
import { hasPrivilege } from '@things-factory/auth-base/dist-client'
|
|
8
|
-
|
|
9
|
-
/** A counterparty as one picks it - which one, its name and registration number (`counterpartyChoices`). */
|
|
10
|
-
export type CounterpartyPick = { id: string; name: string; businessNumber?: string | null; kind?: string | null }
|
|
11
|
-
|
|
12
|
-
/** Registering a counterparty is the counterparty keeper's - the privilege `createCounterparty` asks (ADR-0195 decision 5). */
|
|
13
|
-
export const COUNTERPARTY_REGISTER_PRIVILEGE = { category: 'counterparty', privilege: 'mutation', domainOwnerGranted: true }
|
|
14
|
-
|
|
15
|
-
/** Whether this seat may register a counterparty - where it is not, the pickers offer no registering. */
|
|
16
|
-
export async function mayRegisterCounterparty(): Promise<boolean> {
|
|
17
|
-
try {
|
|
18
|
-
return !!(await hasPrivilege(COUNTERPARTY_REGISTER_PRIVILEGE))
|
|
19
|
-
} catch {
|
|
20
|
-
return false
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Register a counterparty from the name a picker was searched by, in the short form (ADR-0195 decision 3). Resolves the
|
|
26
|
-
* counterparty to take - the one registered, or the one of the same name the form led to - or undefined when the
|
|
27
|
-
* person closed the form.
|
|
28
|
-
*/
|
|
29
|
-
export function registerCounterparty(name: string): Promise<CounterpartyPick | undefined> {
|
|
30
|
-
return new Promise(resolve => {
|
|
31
|
-
let taken: CounterpartyPick | undefined
|
|
32
|
-
const handle: any = openPopup(
|
|
33
|
-
html`<counterparty-register-form
|
|
34
|
-
.name=${name}
|
|
35
|
-
@close=${() => handle.close()}
|
|
36
|
-
@counterparty=${(e: CustomEvent) => ((taken = e.detail), handle.close())}
|
|
37
|
-
></counterparty-register-form>`,
|
|
38
|
-
{ backdrop: true, size: 'medium', title: i18next.t('title.counterparty-register') }
|
|
39
|
-
)
|
|
40
|
-
handle.onclosed = () => resolve(taken)
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* What a picker column of counterparties declares so a name not found can be registered there (`resource-object`'s
|
|
46
|
-
* `creatable`, ADR-0195 decision 2).
|
|
47
|
-
*/
|
|
48
|
-
export const counterpartyCreatable = {
|
|
49
|
-
allowed: mayRegisterCounterparty,
|
|
50
|
-
label: (name: string) => i18next.t('button.counterparty-register-named', { name }),
|
|
51
|
-
create: registerCounterparty
|
|
52
|
-
}
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import '@material/web/icon/icon.js'
|
|
2
|
-
|
|
3
|
-
import gql from 'graphql-tag'
|
|
4
|
-
import { css, html, LitElement, nothing } from 'lit'
|
|
5
|
-
import { customElement, property, state } from 'lit/decorators.js'
|
|
6
|
-
|
|
7
|
-
import { QueryController } from '@operato/graphql'
|
|
8
|
-
import { i18next, localize } from '@operato/i18n'
|
|
9
|
-
import { ButtonStyles } from '@operato/styles'
|
|
10
|
-
import { mayRegisterCounterparty, registerCounterparty, type CounterpartyPick } from './counterparty-register.js'
|
|
11
|
-
|
|
12
|
-
const CHOICES = gql`
|
|
13
|
-
query ($search: String, $pagination: Pagination) {
|
|
14
|
-
counterparties: counterpartyChoices(search: $search, pagination: $pagination) {
|
|
15
|
-
items { id name businessNumber }
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
`
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Picking a counterparty - one field that finds as it is typed and lists what it found under it; a click takes one and
|
|
22
|
-
* fires `counterparty` with it (or with null when cleared). Every form that picks one counterparty picks it here -
|
|
23
|
-
* invoice, quotation, opportunity, expenditure request (ADR-0195 decision 1). Reads `counterpartyChoices`, which every
|
|
24
|
-
* seat may.
|
|
25
|
-
*
|
|
26
|
-
* A name not found can be registered from here and is taken at once (ADR-0195 decision 2) - offered only to a seat that
|
|
27
|
-
* may register counterparties.
|
|
28
|
-
*/
|
|
29
|
-
@customElement('counterparty-select')
|
|
30
|
-
export class CounterpartySelect extends localize(i18next)(LitElement) {
|
|
31
|
-
static styles = [
|
|
32
|
-
ButtonStyles,
|
|
33
|
-
css`
|
|
34
|
-
:host {
|
|
35
|
-
position: relative;
|
|
36
|
-
display: block;
|
|
37
|
-
}
|
|
38
|
-
.field {
|
|
39
|
-
display: flex;
|
|
40
|
-
gap: var(--spacing-small, 4px);
|
|
41
|
-
align-items: center;
|
|
42
|
-
}
|
|
43
|
-
input {
|
|
44
|
-
flex: 1;
|
|
45
|
-
min-width: 0;
|
|
46
|
-
box-sizing: border-box;
|
|
47
|
-
height: var(--form-element-height-medium, 32px);
|
|
48
|
-
padding: 0 var(--spacing-medium, 8px);
|
|
49
|
-
border: var(--input-field-border, 1px solid var(--md-sys-color-outline));
|
|
50
|
-
border-radius: var(--input-field-border-radius, var(--md-sys-shape-corner-small, 4px));
|
|
51
|
-
background: var(--input-field-background, var(--md-sys-color-surface-container-highest));
|
|
52
|
-
font: inherit;
|
|
53
|
-
font-size: var(--ui-t-body, 13px);
|
|
54
|
-
color: var(--ui-ink, var(--md-sys-color-on-surface));
|
|
55
|
-
}
|
|
56
|
-
input:focus-visible {
|
|
57
|
-
outline: none;
|
|
58
|
-
border-color: var(--md-sys-color-primary);
|
|
59
|
-
}
|
|
60
|
-
ul {
|
|
61
|
-
position: absolute;
|
|
62
|
-
z-index: 10;
|
|
63
|
-
left: 0;
|
|
64
|
-
right: 0;
|
|
65
|
-
top: calc(100% + 2px);
|
|
66
|
-
max-height: 260px;
|
|
67
|
-
overflow-y: auto;
|
|
68
|
-
margin: 0;
|
|
69
|
-
padding: var(--spacing-small, 4px) 0;
|
|
70
|
-
list-style: none;
|
|
71
|
-
border: 1px solid var(--md-sys-color-outline-variant);
|
|
72
|
-
border-radius: var(--ui-r, 10px);
|
|
73
|
-
background: var(--md-sys-color-surface-container-lowest);
|
|
74
|
-
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
|
|
75
|
-
}
|
|
76
|
-
li {
|
|
77
|
-
display: flex;
|
|
78
|
-
justify-content: space-between;
|
|
79
|
-
gap: var(--spacing-large, 12px);
|
|
80
|
-
padding: 6px var(--spacing-large, 12px);
|
|
81
|
-
cursor: pointer;
|
|
82
|
-
font-size: var(--ui-t-body, 13px);
|
|
83
|
-
color: var(--ui-ink, var(--md-sys-color-on-surface));
|
|
84
|
-
}
|
|
85
|
-
li:hover,
|
|
86
|
-
li[active] {
|
|
87
|
-
background: var(--md-sys-color-surface-container-high);
|
|
88
|
-
}
|
|
89
|
-
li small {
|
|
90
|
-
white-space: nowrap;
|
|
91
|
-
}
|
|
92
|
-
li small,
|
|
93
|
-
li.none {
|
|
94
|
-
color: var(--ui-muted, var(--md-sys-color-on-surface-variant));
|
|
95
|
-
}
|
|
96
|
-
li.none {
|
|
97
|
-
cursor: default;
|
|
98
|
-
}
|
|
99
|
-
li.register {
|
|
100
|
-
border-top: 1px solid var(--md-sys-color-outline-variant);
|
|
101
|
-
color: var(--ui-accent, var(--md-sys-color-primary));
|
|
102
|
-
}
|
|
103
|
-
`
|
|
104
|
-
]
|
|
105
|
-
|
|
106
|
-
/** The party chosen, shown as the field's placeholder until something is typed. */
|
|
107
|
-
@property({ attribute: false }) party: CounterpartyPick | null = null
|
|
108
|
-
@property({ type: Boolean }) disabled = false
|
|
109
|
-
|
|
110
|
-
@state() private search = ''
|
|
111
|
-
/** The words the list is found by - undefined while no list is open. */
|
|
112
|
-
@state() private finding?: string
|
|
113
|
-
@state() private active = 0
|
|
114
|
-
/** Whether this seat may register a counterparty - the action under the list shows only then. */
|
|
115
|
-
@state() private mayRegister = false
|
|
116
|
-
|
|
117
|
-
private timer?: ReturnType<typeof setTimeout>
|
|
118
|
-
/* A name was registered from here: the focus the form hands back does not open the list again - typing or a click does. */
|
|
119
|
-
private registering = false
|
|
120
|
-
|
|
121
|
-
/* The choices for the words found by - only the answer to the last thing typed is shown, and the list found before
|
|
122
|
-
stays while the next is read (ADR-0190). */
|
|
123
|
-
private choices = new QueryController(this, CHOICES, {
|
|
124
|
-
keepPrevious: true,
|
|
125
|
-
variables: () =>
|
|
126
|
-
this.finding === undefined || this.disabled ? undefined : { search: this.finding.trim() || undefined, pagination: { page: 1, limit: 30 } }
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
/** The list under the field: what was found, or null while it is closed or not read. */
|
|
130
|
-
async connectedCallback() {
|
|
131
|
-
super.connectedCallback()
|
|
132
|
-
this.mayRegister = await mayRegisterCounterparty()
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** The words a new counterparty would be registered under - shown under the list when this seat may register. */
|
|
136
|
-
private get newName(): string {
|
|
137
|
-
return this.mayRegister && this.found ? this.search.trim() : ''
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private get found(): CounterpartyPick[] | null {
|
|
141
|
-
if (this.finding === undefined || !this.choices.data) return null
|
|
142
|
-
return this.choices.data.counterparties?.items ?? []
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
render() {
|
|
146
|
-
return html`
|
|
147
|
-
<div class="field">
|
|
148
|
-
<input
|
|
149
|
-
.value=${this.search}
|
|
150
|
-
placeholder=${this.party?.name ?? i18next.t('text.counterparty-search')}
|
|
151
|
-
aria-label=${i18next.t('field.counterparty')}
|
|
152
|
-
?disabled=${this.disabled}
|
|
153
|
-
@focus=${() => !this.registering && this.find()}
|
|
154
|
-
@mousedown=${() => (this.registering = false)}
|
|
155
|
-
@input=${(e: any) => ((this.registering = false), (this.search = e.target.value), this.findSoon())}
|
|
156
|
-
@keydown=${(e: KeyboardEvent) => this.key(e)}
|
|
157
|
-
@blur=${() => setTimeout(() => (this.finding = undefined), 150)}
|
|
158
|
-
/>
|
|
159
|
-
${this.party && !this.disabled
|
|
160
|
-
? html`<button quiet icon-only title=${i18next.t('button.counterparty-clear')} aria-label=${i18next.t('button.counterparty-clear')} @click=${() => this.choose(null)}>
|
|
161
|
-
<md-icon>close</md-icon>
|
|
162
|
-
</button>`
|
|
163
|
-
: nothing}
|
|
164
|
-
</div>
|
|
165
|
-
${this.found
|
|
166
|
-
? html`<ul role="listbox">
|
|
167
|
-
${this.found.length
|
|
168
|
-
? this.found.map(
|
|
169
|
-
(one, index) =>
|
|
170
|
-
html`<li role="option" ?active=${index === this.active} @mousedown=${(e: Event) => (e.preventDefault(), this.choose(one))}>
|
|
171
|
-
<span>${one.name}</span>${one.businessNumber ? html`<small>${one.businessNumber}</small>` : nothing}
|
|
172
|
-
</li>`
|
|
173
|
-
)
|
|
174
|
-
: html`<li class="none">${i18next.t('text.counterparty-none')}</li>`}
|
|
175
|
-
${this.newName
|
|
176
|
-
? html`<li role="option" class="register" ?active=${this.active === this.found.length} @mousedown=${(e: Event) => (e.preventDefault(), this.register())}>
|
|
177
|
-
<span>${i18next.t('button.counterparty-register-named', { name: this.newName })}</span>
|
|
178
|
-
</li>`
|
|
179
|
-
: nothing}
|
|
180
|
-
</ul>`
|
|
181
|
-
: nothing}
|
|
182
|
-
`
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
private findSoon() {
|
|
186
|
-
clearTimeout(this.timer)
|
|
187
|
-
this.timer = setTimeout(() => this.find(), 250)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
private find() {
|
|
191
|
-
if (this.disabled) return
|
|
192
|
-
this.finding = this.search
|
|
193
|
-
this.active = 0
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
private key(e: KeyboardEvent) {
|
|
197
|
-
const last = (this.found?.length ?? 0) + (this.newName ? 1 : 0) - 1
|
|
198
|
-
if (last < 0 || e.isComposing) return
|
|
199
|
-
if (e.key === 'ArrowDown') this.active = Math.min(this.active + 1, last)
|
|
200
|
-
else if (e.key === 'ArrowUp') this.active = Math.max(this.active - 1, 0)
|
|
201
|
-
else if (e.key === 'Enter') this.active < this.found!.length ? this.choose(this.found![this.active]) : this.register()
|
|
202
|
-
else if (e.key === 'Escape') this.finding = undefined
|
|
203
|
-
else return
|
|
204
|
-
e.preventDefault()
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/** Register the name typed and take it - or the counterparty of that name the form led to. */
|
|
208
|
-
private async register() {
|
|
209
|
-
const name = this.newName
|
|
210
|
-
this.finding = undefined
|
|
211
|
-
this.registering = true
|
|
212
|
-
const registered = await registerCounterparty(name)
|
|
213
|
-
if (registered) this.choose(registered)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
private choose(party: CounterpartyPick | null) {
|
|
217
|
-
this.search = ''
|
|
218
|
-
this.finding = undefined
|
|
219
|
-
this.dispatchEvent(new CustomEvent('counterparty', { detail: party, bubbles: true, composed: true }))
|
|
220
|
-
}
|
|
221
|
-
}
|
package/client/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { CounterpartySelect } from './counterparty-select.js'
|
|
2
|
-
export { CounterpartyRegisterForm } from './counterparty-register-form.js'
|
|
3
|
-
export {
|
|
4
|
-
COUNTERPARTY_REGISTER_PRIVILEGE,
|
|
5
|
-
counterpartyCreatable,
|
|
6
|
-
mayRegisterCounterparty,
|
|
7
|
-
registerCounterparty,
|
|
8
|
-
type CounterpartyPick
|
|
9
|
-
} from './counterparty-register.js'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"counterparty-register-form.js","sourceRoot":"","sources":["../client/counterparty-register-form.ts"],"names":[],"mappings":";AAAA,OAAO,uCAAuC,CAAA;AAC9C,O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nB;IAAhB,KAAK,EAAE;;uDAAmB;AAtDhB,wBAAwB;IADpC,aAAa,CAAC,4BAA4B,CAAC;GAC/B,wBAAwB,CAwKpC","sourcesContent":["import '@material/web/button/filled-button.js'\nimport '@material/web/button/text-button.js'\nimport '@operato/input/ox-input-select-buttons.js'\nimport '@operato/popup/ox-popup-actions.js'\n\nimport gql from 'graphql-tag'\nimport { css, html, LitElement, nothing } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { gqlContext, MutationController, QueryController } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { CommonPopupStyles, FormFieldStyles, PopupBodyStyles, PopupFieldStyles } from '@operato/styles'\n\n/** The kinds a counterparty registered here may be - our own company is one per domain and kept on its own screen. */\nconst KINDS = ['COMPANY', 'INSTITUTION', 'PERSON']\n\nconst SAME_NAMED = gql`\n query ($name: String!) {\n counterpartiesNamed(name: $name) {\n id\n name\n kind\n businessNumber\n }\n }\n`\n\nconst REGISTER = gql`\n mutation ($counterparty: NewCounterparty!) {\n createCounterparty(counterparty: $counterparty) {\n id\n name\n kind\n businessNumber\n }\n }\n`\n\n/**\n * Create a counterparty from the picker through createCounterparty. Collect name, kind and known\n * registration details; emit counterparty on selection and close on cancellation. For a normalized existing\n * name or alias, offer the existing record instead of creating a duplicate (ADR-0195).\n */\n@customElement('counterparty-register-form')\nexport class CounterpartyRegisterForm extends localize(i18next)(LitElement) {\n /* The shared popup layout (page-standard sections 7, 8): only the body scrolls, labels above native inputs. */\n static styles = [\n CommonPopupStyles,\n PopupBodyStyles,\n FormFieldStyles,\n PopupFieldStyles,\n css`\n ox-input-select-buttons {\n align-self: flex-start;\n }\n\n [guide] {\n margin: 0;\n color: var(--ui-muted);\n line-height: var(--popup-line-height);\n }\n\n [invalid] {\n color: var(--ui-crit, var(--md-sys-color-error));\n font-size: var(--ui-t-small, 11.5px);\n }\n\n [invalid]:empty {\n display: none;\n }\n\n ul[same] {\n list-style: none;\n margin: 0;\n padding: 0;\n }\n\n ul[same] li {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: var(--spacing-medium, 8px);\n padding: 3px 0;\n }\n\n ul[same] small {\n color: var(--ui-muted);\n }\n `\n ]\n\n /** The name the picker was searched by - the form starts from it. */\n @property({ type: String }) name = ''\n\n @state() private kind = 'COMPANY'\n @state() private businessNumber = ''\n @state() private representative = ''\n /** The name asked about - set once the person stops typing. */\n @state() private asked = ''\n\n private timer?: ReturnType<typeof setTimeout>\n\n private sameNamed = new QueryController(this, SAME_NAMED, {\n variables: () => (this.asked ? { name: this.asked } : undefined),\n fetchPolicy: 'no-cache',\n context: gqlContext()\n } as any)\n\n private save = new MutationController(this, REGISTER, { context: gqlContext(), showsError: true } as any)\n\n connectedCallback() {\n super.connectedCallback()\n this.asked = this.name.trim()\n }\n\n /** What the name check says for the name now in the field. */\n private get check(): 'idle' | 'checking' | 'free' | 'taken' | 'failed' {\n const name = this.name.trim()\n if (!name || this.asked !== name) return 'idle'\n if (this.sameNamed.loading) return 'checking'\n const found = this.sameNamed.error ? undefined : this.sameNamed.data?.counterpartiesNamed\n if (!Array.isArray(found)) return 'failed'\n return found.length ? 'taken' : 'free'\n }\n\n private get registrable(): boolean {\n return this.check === 'free' && !this.save.pending\n }\n\n render() {\n const check = this.check\n return html`\n <div class=\"body\">\n <p guide>${i18next.t('text.counterparty-register-guide')}</p>\n\n <label class=\"field\">\n <span>${i18next.t('field.counterparty-name')}</span>\n <input name=\"name\" .value=${this.name} @input=${(e: Event) => this.onName((e.target as HTMLInputElement).value)} />\n <span invalid\n >${check === 'failed' ? i18next.t('text.counterparty-name-check-failed') : check === 'checking' ? i18next.t('text.counterparty-checking-name') : ''}</span\n >\n </label>\n\n ${check === 'taken' ? this.renderSameNamed() : nothing}\n\n <div class=\"field\">\n <span>${i18next.t('field.counterparty-kind')}</span>\n <ox-input-select-buttons\n .value=${this.kind}\n .options=${KINDS.map(kind => ({ display: i18next.t(`text.counterparty-kind-${kind.toLowerCase()}`), value: kind }))}\n @change=${(e: CustomEvent) => e.detail && (this.kind = e.detail)}\n ></ox-input-select-buttons>\n </div>\n\n <label class=\"field\">\n <span>${i18next.t('field.business-number')}</span>\n <input name=\"businessNumber\" .value=${this.businessNumber} inputmode=\"numeric\" @input=${(e: Event) => (this.businessNumber = (e.target as HTMLInputElement).value)} />\n <span>${i18next.t('text.business-number-hint')}</span>\n </label>\n\n <label class=\"field\">\n <span>${i18next.t('field.representative')}</span>\n <input name=\"representative\" .value=${this.representative} @input=${(e: Event) => (this.representative = (e.target as HTMLInputElement).value)} />\n </label>\n </div>\n\n <ox-popup-actions>\n <md-text-button slot=\"cancel\" @click=${() => this.dispatchEvent(new CustomEvent('close'))}>${i18next.t('button.cancel')}</md-text-button>\n <md-filled-button slot=\"confirm\" ?disabled=${!this.registrable} @click=${() => this.register()}>${i18next.t('button.counterparty-register')}</md-filled-button>\n </ox-popup-actions>\n `\n }\n\n private renderSameNamed() {\n const found: any[] = this.sameNamed.data?.counterpartiesNamed ?? []\n return html`\n <div class=\"field\">\n <span invalid>${i18next.t('text.counterparty-same-named')}</span>\n <ul same>\n ${found.map(\n one => html`<li>\n <span>${one.name} ${one.businessNumber ? html`<small>${one.businessNumber}</small>` : nothing}</span>\n <md-text-button @click=${() => this.take(one)}>${i18next.t('button.counterparty-choose-this')}</md-text-button>\n </li>`\n )}\n </ul>\n </div>\n `\n }\n\n private onName(value: string) {\n this.name = value\n clearTimeout(this.timer)\n this.timer = setTimeout(() => (this.asked = this.name.trim()), 300)\n }\n\n private async register() {\n if (!this.registrable) return\n const counterparty = {\n name: this.name.trim(),\n kind: this.kind,\n ...(this.businessNumber.trim() ? { businessNumber: this.businessNumber.trim() } : {}),\n ...(this.representative.trim() ? { representative: this.representative.trim() } : {})\n }\n const data: any = await this.save.run({ counterparty })\n const saved = data?.createCounterparty\n if (saved) this.take(saved)\n }\n\n private take(one: { id: string; name: string; businessNumber?: string | null; kind?: string | null }) {\n this.dispatchEvent(new CustomEvent('counterparty', { detail: { id: one.id, name: one.name, businessNumber: one.businessNumber ?? null, kind: one.kind ?? null } }))\n }\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"counterparty-register.js","sourceRoot":"","sources":["../client/counterparty-register.ts"],"names":[],"mappings":"AAAA,OAAO,iCAAiC,CAAA;AAExC,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAE1B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAA;AAKpE,+HAA+H;AAC/H,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAA;AAE5H,yGAAyG;AACzG,MAAM,CAAC,KAAK,UAAU,uBAAuB;IAC3C,IAAI,CAAC;QACH,OAAO,CAAC,CAAC,CAAC,MAAM,YAAY,CAAC,+BAA+B,CAAC,CAAC,CAAA;IAChE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;QAC3B,IAAI,KAAmC,CAAA;QACvC,MAAM,MAAM,GAAQ,SAAS,CAC3B,IAAI,CAAA;gBACM,IAAI;iBACH,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE;wBACb,CAAC,CAAc,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;qCAC3C,EAC/B,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC,EAAE,CACpF,CAAA;QACD,MAAM,CAAC,QAAQ,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,OAAO,EAAE,uBAAuB;IAChC,KAAK,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,oCAAoC,EAAE,EAAE,IAAI,EAAE,CAAC;IAClF,MAAM,EAAE,oBAAoB;CAC7B,CAAA","sourcesContent":["import './counterparty-register-form.js'\n\nimport { html } from 'lit'\n\nimport { i18next } from '@operato/i18n'\nimport { openPopup } from '@operato/layout'\nimport { hasPrivilege } from '@things-factory/auth-base/dist-client'\n\n/** A counterparty as one picks it - which one, its name and registration number (`counterpartyChoices`). */\nexport type CounterpartyPick = { id: string; name: string; businessNumber?: string | null; kind?: string | null }\n\n/** Registering a counterparty is the counterparty keeper's - the privilege `createCounterparty` asks (ADR-0195 decision 5). */\nexport const COUNTERPARTY_REGISTER_PRIVILEGE = { category: 'counterparty', privilege: 'mutation', domainOwnerGranted: true }\n\n/** Whether this seat may register a counterparty - where it is not, the pickers offer no registering. */\nexport async function mayRegisterCounterparty(): Promise<boolean> {\n try {\n return !!(await hasPrivilege(COUNTERPARTY_REGISTER_PRIVILEGE))\n } catch {\n return false\n }\n}\n\n/**\n * Register a counterparty from the name a picker was searched by, in the short form (ADR-0195 decision 3). Resolves the\n * counterparty to take - the one registered, or the one of the same name the form led to - or undefined when the\n * person closed the form.\n */\nexport function registerCounterparty(name: string): Promise<CounterpartyPick | undefined> {\n return new Promise(resolve => {\n let taken: CounterpartyPick | undefined\n const handle: any = openPopup(\n html`<counterparty-register-form\n .name=${name}\n @close=${() => handle.close()}\n @counterparty=${(e: CustomEvent) => ((taken = e.detail), handle.close())}\n ></counterparty-register-form>`,\n { backdrop: true, size: 'medium', title: i18next.t('title.counterparty-register') }\n )\n handle.onclosed = () => resolve(taken)\n })\n}\n\n/**\n * What a picker column of counterparties declares so a name not found can be registered there (`resource-object`'s\n * `creatable`, ADR-0195 decision 2).\n */\nexport const counterpartyCreatable = {\n allowed: mayRegisterCounterparty,\n label: (name: string) => i18next.t('button.counterparty-register-named', { name }),\n create: registerCounterparty\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"counterparty-select.js","sourceRoot":"","sources":["../client/counterparty-select.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AAEnC,OAAO,GAAG,MAAM,aAAa,CAAA;AAC7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAyB,MAAM,4BAA4B,CAAA;AAEjH,MAAM,OAAO,GAAG,GAAG,CAAA;;;;;;CAMlB,CAAA;AAED;;;;;;;;GAQG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;IAA9D;;QA4EL,mFAAmF;QACnD,UAAK,GAA4B,IAAI,CAAA;QACxC,aAAQ,GAAG,KAAK,CAAA;QAE5B,WAAM,GAAG,EAAE,CAAA;QAGX,WAAM,GAAG,CAAC,CAAA;QAC3B,iGAAiG;QAChF,gBAAW,GAAG,KAAK,CAAA;QAGpC,2HAA2H;QACnH,gBAAW,GAAG,KAAK,CAAA;QAE3B;sDAC8C;QACtC,YAAO,GAAG,I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,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IACvG,CAAC;;AAjH+B;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;;iDAAsC;AACxC;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;oDAAiB;AAE5B;IAAhB,KAAK,EAAE;;kDAAoB;AAEX;IAAhB,KAAK,EAAE;;mDAAyB;AAChB;IAAhB,KAAK,EAAE;;kDAAmB;AAEV;IAAhB,KAAK,EAAE;;uDAA4B;AArFzB,kBAAkB;IAD9B,aAAa,CAAC,qBAAqB,CAAC;GACxB,kBAAkB,CA+L9B","sourcesContent":["import '@material/web/icon/icon.js'\n\nimport gql from 'graphql-tag'\nimport { css, html, LitElement, nothing } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { QueryController } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { ButtonStyles } from '@operato/styles'\nimport { mayRegisterCounterparty, registerCounterparty, type CounterpartyPick } from './counterparty-register.js'\n\nconst CHOICES = gql`\n query ($search: String, $pagination: Pagination) {\n counterparties: counterpartyChoices(search: $search, pagination: $pagination) {\n items { id name businessNumber }\n }\n }\n`\n\n/**\n * Picking a counterparty - one field that finds as it is typed and lists what it found under it; a click takes one and\n * fires `counterparty` with it (or with null when cleared). Every form that picks one counterparty picks it here -\n * invoice, quotation, opportunity, expenditure request (ADR-0195 decision 1). Reads `counterpartyChoices`, which every\n * seat may.\n *\n * A name not found can be registered from here and is taken at once (ADR-0195 decision 2) - offered only to a seat that\n * may register counterparties.\n */\n@customElement('counterparty-select')\nexport class CounterpartySelect extends localize(i18next)(LitElement) {\n static styles = [\n ButtonStyles,\n css`\n :host {\n position: relative;\n display: block;\n }\n .field {\n display: flex;\n gap: var(--spacing-small, 4px);\n align-items: center;\n }\n input {\n flex: 1;\n min-width: 0;\n box-sizing: border-box;\n height: var(--form-element-height-medium, 32px);\n padding: 0 var(--spacing-medium, 8px);\n border: var(--input-field-border, 1px solid var(--md-sys-color-outline));\n border-radius: var(--input-field-border-radius, var(--md-sys-shape-corner-small, 4px));\n background: var(--input-field-background, var(--md-sys-color-surface-container-highest));\n font: inherit;\n font-size: var(--ui-t-body, 13px);\n color: var(--ui-ink, var(--md-sys-color-on-surface));\n }\n input:focus-visible {\n outline: none;\n border-color: var(--md-sys-color-primary);\n }\n ul {\n position: absolute;\n z-index: 10;\n left: 0;\n right: 0;\n top: calc(100% + 2px);\n max-height: 260px;\n overflow-y: auto;\n margin: 0;\n padding: var(--spacing-small, 4px) 0;\n list-style: none;\n border: 1px solid var(--md-sys-color-outline-variant);\n border-radius: var(--ui-r, 10px);\n background: var(--md-sys-color-surface-container-lowest);\n box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);\n }\n li {\n display: flex;\n justify-content: space-between;\n gap: var(--spacing-large, 12px);\n padding: 6px var(--spacing-large, 12px);\n cursor: pointer;\n font-size: var(--ui-t-body, 13px);\n color: var(--ui-ink, var(--md-sys-color-on-surface));\n }\n li:hover,\n li[active] {\n background: var(--md-sys-color-surface-container-high);\n }\n li small {\n white-space: nowrap;\n }\n li small,\n li.none {\n color: var(--ui-muted, var(--md-sys-color-on-surface-variant));\n }\n li.none {\n cursor: default;\n }\n li.register {\n border-top: 1px solid var(--md-sys-color-outline-variant);\n color: var(--ui-accent, var(--md-sys-color-primary));\n }\n `\n ]\n\n /** The party chosen, shown as the field's placeholder until something is typed. */\n @property({ attribute: false }) party: CounterpartyPick | null = null\n @property({ type: Boolean }) disabled = false\n\n @state() private search = ''\n /** The words the list is found by - undefined while no list is open. */\n @state() private finding?: string\n @state() private active = 0\n /** Whether this seat may register a counterparty - the action under the list shows only then. */\n @state() private mayRegister = false\n\n private timer?: ReturnType<typeof setTimeout>\n /* A name was registered from here: the focus the form hands back does not open the list again - typing or a click does. */\n private registering = false\n\n /* The choices for the words found by - only the answer to the last thing typed is shown, and the list found before\n stays while the next is read (ADR-0190). */\n private choices = new QueryController(this, CHOICES, {\n keepPrevious: true,\n variables: () =>\n this.finding === undefined || this.disabled ? undefined : { search: this.finding.trim() || undefined, pagination: { page: 1, limit: 30 } }\n })\n\n /** The list under the field: what was found, or null while it is closed or not read. */\n async connectedCallback() {\n super.connectedCallback()\n this.mayRegister = await mayRegisterCounterparty()\n }\n\n /** The words a new counterparty would be registered under - shown under the list when this seat may register. */\n private get newName(): string {\n return this.mayRegister && this.found ? this.search.trim() : ''\n }\n\n private get found(): CounterpartyPick[] | null {\n if (this.finding === undefined || !this.choices.data) return null\n return this.choices.data.counterparties?.items ?? []\n }\n\n render() {\n return html`\n <div class=\"field\">\n <input\n .value=${this.search}\n placeholder=${this.party?.name ?? i18next.t('text.counterparty-search')}\n aria-label=${i18next.t('field.counterparty')}\n ?disabled=${this.disabled}\n @focus=${() => !this.registering && this.find()}\n @mousedown=${() => (this.registering = false)}\n @input=${(e: any) => ((this.registering = false), (this.search = e.target.value), this.findSoon())}\n @keydown=${(e: KeyboardEvent) => this.key(e)}\n @blur=${() => setTimeout(() => (this.finding = undefined), 150)}\n />\n ${this.party && !this.disabled\n ? html`<button quiet icon-only title=${i18next.t('button.counterparty-clear')} aria-label=${i18next.t('button.counterparty-clear')} @click=${() => this.choose(null)}>\n <md-icon>close</md-icon>\n </button>`\n : nothing}\n </div>\n ${this.found\n ? html`<ul role=\"listbox\">\n ${this.found.length\n ? this.found.map(\n (one, index) =>\n html`<li role=\"option\" ?active=${index === this.active} @mousedown=${(e: Event) => (e.preventDefault(), this.choose(one))}>\n <span>${one.name}</span>${one.businessNumber ? html`<small>${one.businessNumber}</small>` : nothing}\n </li>`\n )\n : html`<li class=\"none\">${i18next.t('text.counterparty-none')}</li>`}\n ${this.newName\n ? html`<li role=\"option\" class=\"register\" ?active=${this.active === this.found.length} @mousedown=${(e: Event) => (e.preventDefault(), this.register())}>\n <span>${i18next.t('button.counterparty-register-named', { name: this.newName })}</span>\n </li>`\n : nothing}\n </ul>`\n : nothing}\n `\n }\n\n private findSoon() {\n clearTimeout(this.timer)\n this.timer = setTimeout(() => this.find(), 250)\n }\n\n private find() {\n if (this.disabled) return\n this.finding = this.search\n this.active = 0\n }\n\n private key(e: KeyboardEvent) {\n const last = (this.found?.length ?? 0) + (this.newName ? 1 : 0) - 1\n if (last < 0 || e.isComposing) return\n if (e.key === 'ArrowDown') this.active = Math.min(this.active + 1, last)\n else if (e.key === 'ArrowUp') this.active = Math.max(this.active - 1, 0)\n else if (e.key === 'Enter') this.active < this.found!.length ? this.choose(this.found![this.active]) : this.register()\n else if (e.key === 'Escape') this.finding = undefined\n else return\n e.preventDefault()\n }\n\n /** Register the name typed and take it - or the counterparty of that name the form led to. */\n private async register() {\n const name = this.newName\n this.finding = undefined\n this.registering = true\n const registered = await registerCounterparty(name)\n if (registered) this.choose(registered)\n }\n\n private choose(party: CounterpartyPick | null) {\n this.search = ''\n this.finding = undefined\n this.dispatchEvent(new CustomEvent('counterparty', { detail: party, bubbles: true, composed: true }))\n }\n}\n"]}
|
package/dist-client/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAA;AAC1E,OAAO,EACL,+BAA+B,EAC/B,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EAErB,MAAM,4BAA4B,CAAA","sourcesContent":["export { CounterpartySelect } from './counterparty-select.js'\nexport { CounterpartyRegisterForm } from './counterparty-register-form.js'\nexport {\n COUNTERPARTY_REGISTER_PRIVILEGE,\n counterpartyCreatable,\n mayRegisterCounterparty,\n registerCounterparty,\n type CounterpartyPick\n} from './counterparty-register.js'\n"]}
|