@brightspace-ui/core 2.101.3 → 2.103.0
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/README.md +1 -1
- package/components/button/button-icon.js +0 -1
- package/components/button/button-move.js +245 -0
- package/components/button/demo/button-move.html +46 -0
- package/components/list/list-item-drag-handle.js +93 -125
- package/custom-elements.json +60 -0
- package/helpers/localize-core-element.js +2 -2
- package/mixins/{localize-mixin.md → localize/README.md} +69 -9
- package/mixins/localize/demo/localize-mixin-greeting.js +39 -0
- package/mixins/localize/demo/localize-mixin-mission.js +29 -0
- package/mixins/localize/demo/localize-mixin.html +28 -0
- package/mixins/localize/localize-mixin.js +288 -0
- package/mixins/localize-dynamic-mixin.js +1 -42
- package/mixins/localize-mixin.js +1 -169
- package/mixins/localize-static-mixin.js +1 -28
- package/package.json +2 -1
- package/tools/dom-test-helpers.js +4 -3
- package/mixins/demo/localize-mixin.html +0 -19
- package/mixins/demo/localize-test.js +0 -57
package/mixins/localize-mixin.js
CHANGED
|
@@ -1,169 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { dedupeMixin } from '@open-wc/dedupe-mixin';
|
|
3
|
-
import { getDocumentLocaleSettings } from '@brightspace-ui/intl/lib/common.js';
|
|
4
|
-
import IntlMessageFormat from 'intl-messageformat';
|
|
5
|
-
|
|
6
|
-
export const LocalizeMixin = dedupeMixin(superclass => class extends superclass {
|
|
7
|
-
|
|
8
|
-
static get properties() {
|
|
9
|
-
return {
|
|
10
|
-
__resources: { type: Object, attribute: false }
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
static documentLocaleSettings = getDocumentLocaleSettings();
|
|
15
|
-
|
|
16
|
-
constructor() {
|
|
17
|
-
super();
|
|
18
|
-
this.__resourcesLoadedPromise = new Promise((resolve) => {
|
|
19
|
-
let first = true;
|
|
20
|
-
this.__languageChangeCallback = () => {
|
|
21
|
-
if (!this._hasResources()) return;
|
|
22
|
-
const localizeResources = this.constructor._getAllLocalizeResources();
|
|
23
|
-
const resourcesLoadedPromise = Promise.all(localizeResources);
|
|
24
|
-
resourcesLoadedPromise
|
|
25
|
-
.then((results) => {
|
|
26
|
-
if (results.length === 0) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
const resources = {};
|
|
30
|
-
for (const res of results) {
|
|
31
|
-
const language = res.language;
|
|
32
|
-
for (const [key, value] of Object.entries(res.resources)) {
|
|
33
|
-
resources[key] = { language, value };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
this.__resources = resources;
|
|
37
|
-
this._onResourcesChange();
|
|
38
|
-
if (first) {
|
|
39
|
-
resolve();
|
|
40
|
-
first = false;
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
this.__updatedProperties = new Map();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
connectedCallback() {
|
|
50
|
-
super.connectedCallback();
|
|
51
|
-
this.constructor.documentLocaleSettings.addChangeListener(this.__languageChangeCallback);
|
|
52
|
-
this.__languageChangeCallback();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
disconnectedCallback() {
|
|
56
|
-
super.disconnectedCallback();
|
|
57
|
-
this.constructor.documentLocaleSettings.removeChangeListener(this.__languageChangeCallback);
|
|
58
|
-
this.__updatedProperties.clear();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
shouldUpdate(changedProperties) {
|
|
62
|
-
|
|
63
|
-
const hasResources = this._hasResources();
|
|
64
|
-
if (!hasResources) {
|
|
65
|
-
return super.shouldUpdate(changedProperties);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const ready = this.__resources !== undefined;
|
|
69
|
-
if (!ready) {
|
|
70
|
-
changedProperties.forEach((oldValue, propName) => {
|
|
71
|
-
this.__updatedProperties.set(propName, oldValue);
|
|
72
|
-
});
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
this.__updatedProperties.forEach((oldValue, propName) => {
|
|
77
|
-
if (!changedProperties.has(propName)) {
|
|
78
|
-
changedProperties.set(propName, oldValue);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
this.__updatedProperties.clear();
|
|
82
|
-
|
|
83
|
-
return super.shouldUpdate(changedProperties);
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async getUpdateComplete() {
|
|
88
|
-
await super.getUpdateComplete();
|
|
89
|
-
const hasResources = this._hasResources();
|
|
90
|
-
const resourcesLoaded = this.__resources !== undefined;
|
|
91
|
-
if (!hasResources || resourcesLoaded) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
await this.__resourcesLoadedPromise;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
localize(key) {
|
|
98
|
-
|
|
99
|
-
if (!key || !this.__resources) {
|
|
100
|
-
return '';
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const resource = this.__resources[key];
|
|
104
|
-
if (!resource) {
|
|
105
|
-
return '';
|
|
106
|
-
}
|
|
107
|
-
const translatedValue = resource.value;
|
|
108
|
-
|
|
109
|
-
let params = {};
|
|
110
|
-
if (arguments.length > 1 && typeof arguments[1] === 'object') {
|
|
111
|
-
// support for key-value replacements as a single arg
|
|
112
|
-
params = arguments[1];
|
|
113
|
-
} else {
|
|
114
|
-
// legacy support for localize-behavior replacements as many args
|
|
115
|
-
for (let i = 1; i < arguments.length; i += 2) {
|
|
116
|
-
params[arguments[i]] = arguments[i + 1];
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const translatedMessage = new IntlMessageFormat(translatedValue, resource.language);
|
|
121
|
-
let formattedMessage = translatedValue;
|
|
122
|
-
try {
|
|
123
|
-
formattedMessage = translatedMessage.format(params);
|
|
124
|
-
} catch (e) {
|
|
125
|
-
console.error(e);
|
|
126
|
-
}
|
|
127
|
-
return formattedMessage;
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
static _generatePossibleLanguages(config) {
|
|
132
|
-
|
|
133
|
-
if (config?.useBrowserLangs) return navigator.languages.map(e => e.toLowerCase()).concat('en');
|
|
134
|
-
|
|
135
|
-
const { language, fallbackLanguage } = this.documentLocaleSettings;
|
|
136
|
-
const langs = [ language, fallbackLanguage ]
|
|
137
|
-
.filter(e => e)
|
|
138
|
-
.map(e => [ e.toLowerCase(), e.split('-')[0] ])
|
|
139
|
-
.flat();
|
|
140
|
-
|
|
141
|
-
return Array.from(new Set([ ...langs, 'en-us', 'en' ]));
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
static _getAllLocalizeResources(config = this.localizeConfig) {
|
|
145
|
-
let resourcesLoadedPromises = [];
|
|
146
|
-
const superCtor = Object.getPrototypeOf(this);
|
|
147
|
-
// get imported terms for each config, head up the chain to get them all
|
|
148
|
-
if ('_getAllLocalizeResources' in superCtor) {
|
|
149
|
-
const superConfig = Object.prototype.hasOwnProperty.call(superCtor, 'localizeConfig') && superCtor.localizeConfig.importFunc ? superCtor.localizeConfig : config;
|
|
150
|
-
resourcesLoadedPromises = superCtor._getAllLocalizeResources(superConfig);
|
|
151
|
-
}
|
|
152
|
-
if (Object.prototype.hasOwnProperty.call(this, 'getLocalizeResources') || Object.prototype.hasOwnProperty.call(this, 'resources')) {
|
|
153
|
-
const possibleLanguages = this._generatePossibleLanguages(config);
|
|
154
|
-
const res = this.getLocalizeResources(possibleLanguages, config);
|
|
155
|
-
resourcesLoadedPromises.push(res);
|
|
156
|
-
}
|
|
157
|
-
return resourcesLoadedPromises;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
_hasResources() {
|
|
161
|
-
return this.constructor['getLocalizeResources'] !== undefined;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
_onResourcesChange() {
|
|
165
|
-
/** @ignore */
|
|
166
|
-
this.dispatchEvent(new CustomEvent('d2l-localize-resources-change'));
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
});
|
|
1
|
+
export { _LocalizeMixinBase as LocalizeMixin } from './localize/localize-mixin.js';
|
|
@@ -1,28 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const fallbackLang = 'en';
|
|
4
|
-
|
|
5
|
-
export const LocalizeStaticMixin = superclass => class extends LocalizeMixin(superclass) {
|
|
6
|
-
|
|
7
|
-
static async getLocalizeResources(langs) {
|
|
8
|
-
let resolvedLang = fallbackLang;
|
|
9
|
-
const resolvedResources = Object.assign({}, this.resources[fallbackLang]);
|
|
10
|
-
|
|
11
|
-
langs.reverse().forEach((lang) => {
|
|
12
|
-
if (this.resources[lang]) {
|
|
13
|
-
resolvedLang = lang;
|
|
14
|
-
Object.assign(resolvedResources, this.resources[lang]);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
language: resolvedLang,
|
|
20
|
-
resources: resolvedResources
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
static get resources() {
|
|
25
|
-
return { 'en': {} };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
};
|
|
1
|
+
export { LocalizeStaticMixin } from './localize/localize-mixin.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brightspace-ui/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.103.0",
|
|
4
4
|
"description": "A collection of accessible, free, open-source web components for building Brightspace applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "https://github.com/BrightspaceUI/core.git",
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@babel/eslint-parser": "^7",
|
|
48
48
|
"@brightspace-ui/stylelint-config": "^0.7",
|
|
49
|
+
"@open-wc/semantic-dom-diff": "^0.19.9",
|
|
49
50
|
"@open-wc/testing": "^3",
|
|
50
51
|
"@rollup/plugin-dynamic-import-vars": "^2",
|
|
51
52
|
"@rollup/plugin-node-resolve": "^15",
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { getComposedChildren } from '../helpers/dom.js';
|
|
2
2
|
|
|
3
|
-
export function keyDown(element,
|
|
3
|
+
export function keyDown(element, keyCode, ctrlKey) {
|
|
4
4
|
const event = new CustomEvent('keydown', {
|
|
5
5
|
detail: 0,
|
|
6
6
|
bubbles: true,
|
|
7
7
|
cancelable: true,
|
|
8
8
|
composed: true
|
|
9
9
|
});
|
|
10
|
-
event.keyCode =
|
|
11
|
-
event.code =
|
|
10
|
+
event.keyCode = keyCode;
|
|
11
|
+
event.code = keyCode;
|
|
12
|
+
if (ctrlKey !== undefined) event.ctrlKey = ctrlKey;
|
|
12
13
|
element.dispatchEvent(event);
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
5
|
-
<meta charset="UTF-8">
|
|
6
|
-
<link rel="stylesheet" href="../../components/demo/styles.css" type="text/css">
|
|
7
|
-
<script type="module">
|
|
8
|
-
import '../../components/demo/demo-page.js';
|
|
9
|
-
import './localize-test.js';
|
|
10
|
-
</script>
|
|
11
|
-
</head>
|
|
12
|
-
<body unresolved>
|
|
13
|
-
<d2l-demo-page page-title="localize-mixin">
|
|
14
|
-
<d2l-demo-snippet>
|
|
15
|
-
<d2l-test-localize name="Bill"></d2l-test-localize>
|
|
16
|
-
</d2l-demo-snippet>
|
|
17
|
-
</d2l-demo-page>
|
|
18
|
-
</body>
|
|
19
|
-
</html>
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { html, LitElement } from 'lit';
|
|
2
|
-
import { LocalizeDynamicMixin } from '../../mixins/localize-dynamic-mixin.js';
|
|
3
|
-
|
|
4
|
-
class LocalizeTest extends LocalizeDynamicMixin(LitElement) {
|
|
5
|
-
|
|
6
|
-
static get properties() {
|
|
7
|
-
return {
|
|
8
|
-
name: {
|
|
9
|
-
type: String
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
static get localizeConfig() {
|
|
15
|
-
const langResources = {
|
|
16
|
-
'ar': { 'hello': 'مرحبا {name}' },
|
|
17
|
-
'de': { 'hello': 'Hallo {name}' },
|
|
18
|
-
'en': {
|
|
19
|
-
'hello': 'Hello {name}',
|
|
20
|
-
'plural': 'You have {itemCount, plural, =0 {no items} one {1 item} other {{itemCount} items}}.'
|
|
21
|
-
},
|
|
22
|
-
'en-ca': { 'hello': 'Hello, {name} eh' },
|
|
23
|
-
'es': { 'hello': 'Hola {name}' },
|
|
24
|
-
'fr': { 'hello': 'Bonjour {name}' },
|
|
25
|
-
'ja': { 'hello': 'こんにちは {name}' },
|
|
26
|
-
'ko': { 'hello': '안녕하세요 {name}' },
|
|
27
|
-
'pt-br': { 'hello': 'Olá {name}' },
|
|
28
|
-
'tr': { 'hello': 'Merhaba {name}' },
|
|
29
|
-
'zh-cn': { 'hello': '你好 {name}' },
|
|
30
|
-
'zh-tw': { 'hello': '你好 {name}' }
|
|
31
|
-
};
|
|
32
|
-
return {
|
|
33
|
-
importFunc: async lang => {
|
|
34
|
-
return new Promise((resolve) => {
|
|
35
|
-
setTimeout(() => {
|
|
36
|
-
resolve(langResources[lang]);
|
|
37
|
-
}, 50);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
render() {
|
|
44
|
-
requestAnimationFrame(
|
|
45
|
-
() => this.dispatchEvent(new CustomEvent('d2l-test-localize-render', {
|
|
46
|
-
bubbles: false,
|
|
47
|
-
composed: false
|
|
48
|
-
}))
|
|
49
|
-
);
|
|
50
|
-
return html`
|
|
51
|
-
<p>${this.localize('hello', { name: this.name })}</p>
|
|
52
|
-
`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
customElements.define('d2l-test-localize', LocalizeTest);
|