@blockquote-web-components/blockquote-base-meta 1.0.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/LICENSE +21 -0
- package/README.md +79 -0
- package/index.js +1 -0
- package/package.json +131 -0
- package/src/BlockquoteBaseMeta.js +216 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 blockquote-base-meta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# blockquote-base-meta
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
`BlockquoteBaseMeta` is based on Polymer's `iron-meta`, and it is a generic class that you can use
|
|
6
|
+
for sharing information across the DOM tree.
|
|
7
|
+
It uses [monostate pattern](http://c2.com/cgi/wiki?MonostatePattern) pattern such that any instance
|
|
8
|
+
of it has access to the shared information. You can use `BlockquoteBaseMeta` to share whatever you
|
|
9
|
+
want.
|
|
10
|
+
The `BlockquoteBaseMeta` instances contain your actual data. The only requirement is that you
|
|
11
|
+
create them before you try to access them.
|
|
12
|
+
|
|
13
|
+
`BlockquoteBaseMeta` uses [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map).
|
|
14
|
+
|
|
15
|
+
Map is a collection of keyed data items, just like an Object.
|
|
16
|
+
But the main difference is that Map allows keys of any type.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
import { BlockquoteBaseMeta } from '@blockquote-web-components/blockquote-base-meta';
|
|
22
|
+
|
|
23
|
+
const myDefault = new BlockquoteBaseMeta({
|
|
24
|
+
key: 'basic',
|
|
25
|
+
value: 'foo/bar',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
console.log(myDefault.value); // foo/bar
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Keys string - Object
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
import { BlockquoteBaseMeta } from '@blockquote-web-components/blockquote-base-meta';
|
|
35
|
+
|
|
36
|
+
const myDefault = new BlockquoteBaseMeta({
|
|
37
|
+
type: 'one',
|
|
38
|
+
key: 'basic',
|
|
39
|
+
value: 'foo/bar',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
console.log(myDefault.objectList); // {basic: 'foo/bar'}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Keys any type - Map
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
import { BlockquoteBaseMeta } from '@blockquote-web-components/blockquote-base-meta';
|
|
49
|
+
|
|
50
|
+
const keyInfo = { id: 'dsfaskj0' };
|
|
51
|
+
const myDefault = new BlockquoteBaseMeta({
|
|
52
|
+
type: 'two',
|
|
53
|
+
key: keyInfo,
|
|
54
|
+
value: 'foo/bar',
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
console.log(myDefault.mapList); // {{ id: 'dsfaskj0' }: 'foo/bar'}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Properties
|
|
61
|
+
|
|
62
|
+
| Property | Modifiers | Description |
|
|
63
|
+
| ------------ | --------- | ------------------------------------------------------------- |
|
|
64
|
+
| `key` | | Key for Meta |
|
|
65
|
+
| `list` | readonly | Returns a list (Array) of the values for that instance `type` |
|
|
66
|
+
| `mapList` | readonly | Returns a list (Map) for that instance `type` |
|
|
67
|
+
| `objectList` | readonly | Returns a list (Object) for that instance `type` |
|
|
68
|
+
| `type` | | Type of Meta |
|
|
69
|
+
| `value` | | Returns value of instance key and type |
|
|
70
|
+
|
|
71
|
+
## Methods
|
|
72
|
+
|
|
73
|
+
| Method | Type | Description |
|
|
74
|
+
| ------- | ------------- | -------------------------------------------------------------- |
|
|
75
|
+
| `byKey` | `(key: *): *` | Returns the value of the provided key for that instance `type` |
|
|
76
|
+
|
|
77
|
+
## Exports
|
|
78
|
+
|
|
79
|
+
- BlockquoteBaseMeta
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BlockquoteBaseMeta } from './src/BlockquoteBaseMeta.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blockquote-web-components/blockquote-base-meta",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Webcomponent blockquote-base-meta following open-wc recommendations",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"lit",
|
|
7
|
+
"web-component",
|
|
8
|
+
"lit-element"
|
|
9
|
+
],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": "blockquote-base-meta",
|
|
12
|
+
"main": "index.js",
|
|
13
|
+
"module": "index.js",
|
|
14
|
+
"files": [
|
|
15
|
+
"/define/",
|
|
16
|
+
"/src/",
|
|
17
|
+
"index.js",
|
|
18
|
+
"!/**/*.scss"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"analyze": "cem analyze --litelement --globs \"{src,define}/**/*.{js,ts}\" \"index.js\"",
|
|
22
|
+
"analyze:doc": "npm run analyze && npx web-component-analyzer \"{src,define}/**/*.{js,ts}\" \"index.js\" --outFile README.md",
|
|
23
|
+
"build": "echo \"This is not a TypeScript project, so no need to build.\"",
|
|
24
|
+
"dev:vite": "vite build",
|
|
25
|
+
"format": "npm run format:eslint && npm run format:prettier && npm run format:stylelint",
|
|
26
|
+
"format:eslint": "eslint \"**/*.{js,ts,html}\" --fix --ignore-path .eslintignore",
|
|
27
|
+
"format:prettier": "prettier \"**/*.{js,ts,json,html,md}\" --write --ignore-path .eslintignore",
|
|
28
|
+
"format:stylelint": "stylelint \"**/*.{scss,css}\" --fix --allow-empty-input --ignore-path .eslintignore",
|
|
29
|
+
"postinstall": "npm run sort:package",
|
|
30
|
+
"lint": "npm run lint:eslint && npm run lint:prettier && npm run lint:stylelint",
|
|
31
|
+
"lint:eslint": "eslint \"**/*.{js,ts,html}\" --ignore-path .eslintignore",
|
|
32
|
+
"lint:prettier": "prettier \"**/*.{js,ts,json,html,md}\" --check --ignore-path .eslintignore",
|
|
33
|
+
"lint:stylelint": "stylelint \"**/*.{scss,css}\" --allow-empty-input --ignore-path .eslintignore",
|
|
34
|
+
"preview:vite": "vite preview",
|
|
35
|
+
"sass:watch": "sass-style-template",
|
|
36
|
+
"sort:package": "npx sort-package-json",
|
|
37
|
+
"start": "concurrently -k -r \"npm:sass:watch\" \"npm:vite\"",
|
|
38
|
+
"start:wds": "concurrently -k -r \"npm:sass:watch\" \"npm:wds\"",
|
|
39
|
+
"test": "wtr --coverage",
|
|
40
|
+
"test:watch": "wtr --watch",
|
|
41
|
+
"vite": "vite",
|
|
42
|
+
"wds": "web-dev-server"
|
|
43
|
+
},
|
|
44
|
+
"husky": {
|
|
45
|
+
"hooks": {
|
|
46
|
+
"pre-commit": "lint-staged"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"lint-staged": {
|
|
50
|
+
"**/*.{js,ts,html}": [
|
|
51
|
+
"npm run format:eslint"
|
|
52
|
+
],
|
|
53
|
+
"**/*.{js,ts,json,html,md}": [
|
|
54
|
+
"npm run format:prettier"
|
|
55
|
+
],
|
|
56
|
+
"**/*.{scss,css}": [
|
|
57
|
+
"npm run format:stylelint"
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
"prettier": {
|
|
61
|
+
"arrowParens": "avoid",
|
|
62
|
+
"printWidth": 100,
|
|
63
|
+
"singleQuote": true,
|
|
64
|
+
"trailingComma": "all",
|
|
65
|
+
"overrides": [
|
|
66
|
+
{
|
|
67
|
+
"files": "*.{scss,css}",
|
|
68
|
+
"options": {
|
|
69
|
+
"singleQuote": false
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"eslintConfig": {
|
|
75
|
+
"parserOptions": {
|
|
76
|
+
"ecmaVersion": "latest"
|
|
77
|
+
},
|
|
78
|
+
"plugins": [
|
|
79
|
+
"log-filenames"
|
|
80
|
+
],
|
|
81
|
+
"extends": [
|
|
82
|
+
"prettier",
|
|
83
|
+
"@open-wc"
|
|
84
|
+
],
|
|
85
|
+
"rules": {
|
|
86
|
+
"arrow-parens": "off",
|
|
87
|
+
"class-methods-use-this": "off",
|
|
88
|
+
"object-curly-newline": "off",
|
|
89
|
+
"operator-linebreak": [
|
|
90
|
+
"error",
|
|
91
|
+
"after"
|
|
92
|
+
],
|
|
93
|
+
"import/extensions": [
|
|
94
|
+
"error",
|
|
95
|
+
"always",
|
|
96
|
+
{
|
|
97
|
+
"ignorePackages": true
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
"import/no-extraneous-dependencies": [
|
|
101
|
+
"error",
|
|
102
|
+
{
|
|
103
|
+
"devDependencies": [
|
|
104
|
+
"**/test/**/*.{js,ts}",
|
|
105
|
+
"**/*.config.{js,mjs,cjs}",
|
|
106
|
+
"**/*.conf.{js,mjs,cjs}"
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
"import/no-unresolved": "off",
|
|
111
|
+
"import/prefer-default-export": "off"
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"stylelint": {
|
|
115
|
+
"extends": "stylelint-config-standard-scss",
|
|
116
|
+
"rules": {
|
|
117
|
+
"custom-property-pattern": null,
|
|
118
|
+
"max-line-length": null
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"dependencies": {
|
|
122
|
+
"lit": "^2.0.0"
|
|
123
|
+
},
|
|
124
|
+
"devDependencies": {
|
|
125
|
+
"@blockquote-web-components/blockquote-base-common-dev-dependencies": "^1.0.0"
|
|
126
|
+
},
|
|
127
|
+
"publishConfig": {
|
|
128
|
+
"access": "public"
|
|
129
|
+
},
|
|
130
|
+
"customElements": "custom-elements.json"
|
|
131
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@license
|
|
3
|
+
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
|
|
4
|
+
This code may only be used under the BSD style license found at
|
|
5
|
+
http://polymer.github.io/LICENSE.txt The complete set of authors may be found at
|
|
6
|
+
http://polymer.github.io/AUTHORS.txt The complete set of contributors may be
|
|
7
|
+
found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as
|
|
8
|
+
part of the polymer project is also subject to an additional IP rights grant
|
|
9
|
+
found at http://polymer.github.io/PATENTS.txt
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
window[Symbol.for('BLOCKQUOTE')] = window[Symbol.for('BLOCKQUOTE')] || Object.create(null);
|
|
13
|
+
|
|
14
|
+
window[Symbol.for('BLOCKQUOTE')][Symbol.for('blockquoteBaseMeta')] =
|
|
15
|
+
window[Symbol.for('BLOCKQUOTE')][Symbol.for('blockquoteBaseMeta')] || Object.create(null);
|
|
16
|
+
|
|
17
|
+
const symbolBaseMeta = window[Symbol.for('BLOCKQUOTE')][Symbol.for('blockquoteBaseMeta')];
|
|
18
|
+
|
|
19
|
+
symbolBaseMeta[Symbol.for('types')] = symbolBaseMeta[Symbol.for('types')] || new Map();
|
|
20
|
+
|
|
21
|
+
symbolBaseMeta[Symbol.for('uuid')] =
|
|
22
|
+
symbolBaseMeta[Symbol.for('uuid')] || Math.random().toString(36).substr(2, 10);
|
|
23
|
+
|
|
24
|
+
// https://www.oreilly.com/library/view/learning-javascript-design/9781449334840/ch13s15.html
|
|
25
|
+
// https://www.keithcirkel.co.uk/metaprogramming-in-es6-symbols/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+

|
|
29
|
+
|
|
30
|
+
`BlockquoteBaseMeta` is based on Polymer's `iron-meta`, and it is a generic class that you can use
|
|
31
|
+
for sharing information across the DOM tree.
|
|
32
|
+
It uses [monostate pattern](http://c2.com/cgi/wiki?MonostatePattern) pattern such that any instance
|
|
33
|
+
of it has access to the shared information. You can use `BlockquoteBaseMeta` to share whatever you
|
|
34
|
+
want.
|
|
35
|
+
The `BlockquoteBaseMeta` instances contain your actual data. The only requirement is that you
|
|
36
|
+
create them before you try to access them.
|
|
37
|
+
|
|
38
|
+
`BlockquoteBaseMeta` uses [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map).
|
|
39
|
+
|
|
40
|
+
Map is a collection of keyed data items, just like an Object.
|
|
41
|
+
But the main difference is that Map allows keys of any type.
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
import { BlockquoteBaseMeta } from '@blockquote-web-components/blockquote-base-meta';
|
|
47
|
+
|
|
48
|
+
const myDefault = new BlockquoteBaseMeta({
|
|
49
|
+
key: 'basic',
|
|
50
|
+
value: 'foo/bar',
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
console.log(myDefault.value); // foo/bar
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Keys string - Object
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import { BlockquoteBaseMeta } from '@blockquote-web-components/blockquote-base-meta';
|
|
60
|
+
|
|
61
|
+
const myDefault = new BlockquoteBaseMeta({
|
|
62
|
+
type: 'one',
|
|
63
|
+
key: 'basic',
|
|
64
|
+
value: 'foo/bar',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
console.log(myDefault.objectList); // {basic: 'foo/bar'}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Keys any type - Map
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import { BlockquoteBaseMeta } from '@blockquote-web-components/blockquote-base-meta';
|
|
74
|
+
|
|
75
|
+
const keyInfo = { id: 'dsfaskj0' };
|
|
76
|
+
const myDefault = new BlockquoteBaseMeta({
|
|
77
|
+
type: 'two',
|
|
78
|
+
key: keyInfo,
|
|
79
|
+
value: 'foo/bar',
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
console.log(myDefault.mapList); // {{ id: 'dsfaskj0' }: 'foo/bar'}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Properties
|
|
86
|
+
|
|
87
|
+
| Property | Modifiers | Description |
|
|
88
|
+
|--------------|-----------|--------------------------------------------------|
|
|
89
|
+
| `key` | | Key for Meta |
|
|
90
|
+
| `list` | readonly | Returns a list of the values for that instance `type` |
|
|
91
|
+
| `mapList` | readonly | Returns a Map list for that instance `type` |
|
|
92
|
+
| `objectList` | readonly | Returns a Object list for that instance `type` |
|
|
93
|
+
| `type` | | Type of Meta |
|
|
94
|
+
| `value` | | Returns value of instance key and type |
|
|
95
|
+
|
|
96
|
+
## Methods
|
|
97
|
+
|
|
98
|
+
| Method | Type | Description |
|
|
99
|
+
|---------|---------------|--------------------------------------------------|
|
|
100
|
+
| `byKey` | `(key: *): *` | Returns the value of the provided key for that instance `type` |
|
|
101
|
+
|
|
102
|
+
## Exports
|
|
103
|
+
|
|
104
|
+
- BlockquoteBaseMeta
|
|
105
|
+
|
|
106
|
+
*/
|
|
107
|
+
export class BlockquoteBaseMeta {
|
|
108
|
+
/**
|
|
109
|
+
* @param {{
|
|
110
|
+
* type: *,
|
|
111
|
+
* key: *,
|
|
112
|
+
* value: *,
|
|
113
|
+
* }=} options
|
|
114
|
+
*/
|
|
115
|
+
constructor(options) {
|
|
116
|
+
/**
|
|
117
|
+
* Type of Meta
|
|
118
|
+
*/
|
|
119
|
+
this.type = (options && options.type) || 'default';
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Key for Meta
|
|
123
|
+
*/
|
|
124
|
+
this.key = options && options.key;
|
|
125
|
+
if (options && 'value' in options) {
|
|
126
|
+
this.value = options.value;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static get types() {
|
|
131
|
+
return symbolBaseMeta[Symbol.for('types')];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static get uuid() {
|
|
135
|
+
return symbolBaseMeta[Symbol.for('uuid')];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Returns value of instance key and type
|
|
140
|
+
* @return {*}
|
|
141
|
+
*/
|
|
142
|
+
get value() {
|
|
143
|
+
const { type } = this;
|
|
144
|
+
const key = this.__key || this.key;
|
|
145
|
+
this.__key = undefined;
|
|
146
|
+
if (type && key) {
|
|
147
|
+
return BlockquoteBaseMeta.types.get(type) && BlockquoteBaseMeta.types.get(type).get(key);
|
|
148
|
+
}
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Sets value to instance type and key
|
|
154
|
+
* @param {*} value
|
|
155
|
+
*/
|
|
156
|
+
set value(value) {
|
|
157
|
+
const { type } = this;
|
|
158
|
+
const { key } = this;
|
|
159
|
+
let __type;
|
|
160
|
+
if (type && key) {
|
|
161
|
+
if (BlockquoteBaseMeta.types.get(type) === undefined) {
|
|
162
|
+
BlockquoteBaseMeta.types.set(type, new Map());
|
|
163
|
+
}
|
|
164
|
+
__type = BlockquoteBaseMeta.types.get(type);
|
|
165
|
+
if (value === null) {
|
|
166
|
+
__type.delete(key);
|
|
167
|
+
} else {
|
|
168
|
+
__type.set(key, value);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Returns a list (Array) of the values for that instance `type`
|
|
175
|
+
* @return {Array}
|
|
176
|
+
*/
|
|
177
|
+
get list() {
|
|
178
|
+
const { type } = this;
|
|
179
|
+
const itemsType = BlockquoteBaseMeta.types.get(type);
|
|
180
|
+
if (itemsType) {
|
|
181
|
+
return Array.from(itemsType.values());
|
|
182
|
+
}
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Returns a list (Map) for that instance `type`
|
|
188
|
+
* @return {Map}
|
|
189
|
+
*/
|
|
190
|
+
get mapList() {
|
|
191
|
+
const { type } = this;
|
|
192
|
+
const itemsType = BlockquoteBaseMeta.types.get(type);
|
|
193
|
+
if (itemsType) {
|
|
194
|
+
return itemsType;
|
|
195
|
+
}
|
|
196
|
+
return new Map();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Returns a list (Object) for that instance `type`
|
|
201
|
+
* @return {Object}
|
|
202
|
+
*/
|
|
203
|
+
get objectList() {
|
|
204
|
+
return Object.fromEntries(this.mapList);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Returns the value of the provided key for that instance `type`
|
|
209
|
+
* @param {*} key
|
|
210
|
+
* @return {*}
|
|
211
|
+
*/
|
|
212
|
+
byKey(key) {
|
|
213
|
+
this.__key = key;
|
|
214
|
+
return this.value;
|
|
215
|
+
}
|
|
216
|
+
}
|