@pictogrammers/components 0.4.8 → 0.5.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.
Files changed (191) hide show
  1. package/package.json +1 -1
  2. package/pg/annoy/annoy.css +1 -1
  3. package/pg/button/button.css +5 -4
  4. package/pg/buttonLink/buttonLink.css +1 -1
  5. package/pg/buttonMenu/__examples__/basic/basic.ts +2 -2
  6. package/pg/buttonMenu/buttonMenu.ts +4 -1
  7. package/pg/cardUser/cardUser.css +1 -1
  8. package/pg/database/__examples__/basic/basic.ts +0 -1
  9. package/pg/grid/__examples__/basic/basic.ts +1 -4
  10. package/pg/grid/grid.css +1 -1
  11. package/pg/header/header.css +1 -1
  12. package/pg/icon/__examples__/basic/basic.ts +1 -1
  13. package/pg/inputCheck/__examples__/basic/basic.ts +1 -1
  14. package/pg/inputCheck/inputCheck.css +5 -0
  15. package/pg/inputCheck/inputCheck.ts +4 -0
  16. package/pg/inputCheckList/__examples__/basic/basic.ts +1 -1
  17. package/pg/inputFileLocal/inputFileLocal.css +1 -1
  18. package/pg/inputNumber/README.md +27 -0
  19. package/pg/inputNumber/__examples__/basic/basic.html +9 -0
  20. package/pg/inputNumber/__examples__/basic/basic.ts +30 -0
  21. package/pg/inputNumber/inputNumber.css +34 -0
  22. package/pg/inputNumber/inputNumber.html +1 -0
  23. package/pg/inputNumber/inputNumber.spec.ts +59 -0
  24. package/pg/inputNumber/inputNumber.ts +63 -0
  25. package/pg/inputPixelEditor/README.md +211 -29
  26. package/pg/inputPixelEditor/__examples__/basic/basic.css +8 -0
  27. package/pg/inputPixelEditor/__examples__/basic/basic.html +29 -7
  28. package/pg/inputPixelEditor/__examples__/basic/basic.ts +274 -13
  29. package/pg/inputPixelEditor/__examples__/basic/constants.ts +62 -0
  30. package/pg/inputPixelEditor/inputPixelEditor.css +37 -2
  31. package/pg/inputPixelEditor/inputPixelEditor.html +22 -0
  32. package/pg/inputPixelEditor/inputPixelEditor.ts +822 -82
  33. package/pg/inputPixelEditor/utils/bitmapToMask.ts +22 -8
  34. package/pg/inputPixelEditor/utils/blobToImage.ts +11 -0
  35. package/pg/inputPixelEditor/utils/canvasToPngBuffer.ts +12 -0
  36. package/pg/inputPixelEditor/utils/constants.ts +55 -1
  37. package/pg/inputPixelEditor/utils/crc32.ts +116 -0
  38. package/pg/inputPixelEditor/utils/diffMap.ts +32 -0
  39. package/pg/inputPixelEditor/utils/generateGradient.ts +112 -0
  40. package/pg/inputPixelEditor/utils/getEllipsePixels.ts +131 -19
  41. package/pg/inputPixelEditor/utils/getFloodFill.ts +83 -0
  42. package/pg/inputPixelEditor/utils/getGridColorIndexes.ts +13 -0
  43. package/pg/inputPixelEditor/utils/getOutline.ts +92 -0
  44. package/pg/inputPixelEditor/utils/inputMode.ts +7 -1
  45. package/pg/inputPixelEditor/utils/pixelSizes.ts +47 -0
  46. package/pg/inputPixelEditor/utils/pngMetadata.ts +487 -0
  47. package/pg/inputSelect/inputSelect.css +4 -4
  48. package/pg/inputText/inputText.css +14 -7
  49. package/pg/inputText/inputText.ts +5 -1
  50. package/pg/json/README.md +59 -0
  51. package/pg/json/__examples__/basic/basic.html +4 -0
  52. package/pg/json/__examples__/basic/basic.ts +31 -0
  53. package/pg/json/json.css +9 -0
  54. package/pg/json/json.html +1 -0
  55. package/pg/json/json.ts +124 -0
  56. package/pg/jsonArray/README.md +3 -0
  57. package/pg/jsonArray/jsonArray.css +15 -0
  58. package/pg/jsonArray/jsonArray.html +7 -0
  59. package/pg/jsonArray/jsonArray.ts +55 -0
  60. package/pg/jsonBoolean/README.md +3 -0
  61. package/pg/jsonBoolean/jsonBoolean.css +27 -0
  62. package/pg/jsonBoolean/jsonBoolean.html +5 -0
  63. package/pg/jsonBoolean/jsonBoolean.ts +69 -0
  64. package/pg/jsonNumber/README.md +3 -0
  65. package/pg/jsonNumber/jsonNumber.css +21 -0
  66. package/pg/jsonNumber/jsonNumber.html +5 -0
  67. package/pg/jsonNumber/jsonNumber.ts +42 -0
  68. package/pg/jsonObject/README.md +3 -0
  69. package/pg/jsonObject/jsonObject.css +11 -0
  70. package/pg/jsonObject/jsonObject.html +5 -0
  71. package/pg/jsonObject/jsonObject.ts +55 -0
  72. package/pg/jsonString/README.md +3 -0
  73. package/pg/jsonString/jsonString.css +21 -0
  74. package/pg/jsonString/jsonString.html +5 -0
  75. package/pg/jsonString/jsonString.ts +42 -0
  76. package/pg/menu/menu.ts +6 -5
  77. package/pg/menuItem/README.md +13 -2
  78. package/pg/menuItem/menuItem.css +17 -22
  79. package/pg/menuItem/menuItem.ts +8 -3
  80. package/pg/menuItemIcon/__examples__/basic/basic.html +1 -1
  81. package/pg/menuItemIcon/__examples__/basic/basic.ts +7 -0
  82. package/pg/menuItemIcon/menuItemIcon.css +18 -15
  83. package/pg/menuItemIcon/menuItemIcon.ts +8 -4
  84. package/pg/modal/README.md +29 -0
  85. package/pg/modal/__examples__/basic/basic.html +4 -0
  86. package/pg/modal/__examples__/basic/basic.ts +42 -0
  87. package/pg/modal/index.ts +3 -0
  88. package/pg/modal/modal.css +40 -0
  89. package/pg/modal/modal.html +9 -0
  90. package/pg/modal/modal.ts +14 -0
  91. package/pg/modification/__examples__/basic/basic.ts +1 -1
  92. package/pg/overlayMenu/overlayMenu.ts +6 -2
  93. package/pg/overlaySelectMenu/overlaySelectMenu.ts +6 -0
  94. package/pg/overlaySubMenu/overlaySubMenu.ts +6 -2
  95. package/pg/scroll/__examples__/basic/basic.ts +1 -1
  96. package/pg/search/search.css +1 -1
  97. package/pg/table/README.md +108 -0
  98. package/pg/table/__examples__/basic/basic.css +0 -0
  99. package/pg/table/__examples__/basic/basic.html +10 -0
  100. package/pg/table/__examples__/basic/basic.ts +111 -0
  101. package/pg/table/table.css +20 -0
  102. package/pg/table/table.html +6 -0
  103. package/pg/table/table.ts +86 -0
  104. package/pg/tableCellButtonIcon/README.md +3 -0
  105. package/pg/tableCellButtonIcon/tableCellButtonIcon.css +16 -0
  106. package/pg/tableCellButtonIcon/tableCellButtonIcon.html +5 -0
  107. package/pg/tableCellButtonIcon/tableCellButtonIcon.ts +34 -0
  108. package/pg/tableCellCheck/README.md +3 -0
  109. package/pg/tableCellCheck/tableCellCheck.css +15 -0
  110. package/pg/tableCellCheck/tableCellCheck.html +3 -0
  111. package/pg/tableCellCheck/tableCellCheck.ts +43 -0
  112. package/pg/tableCellNumber/README.md +3 -0
  113. package/pg/tableCellNumber/tableCellNumber.css +11 -0
  114. package/pg/tableCellNumber/tableCellNumber.html +3 -0
  115. package/pg/tableCellNumber/tableCellNumber.ts +40 -0
  116. package/pg/tableCellText/README.md +3 -0
  117. package/pg/tableCellText/tableCellText.css +11 -0
  118. package/pg/tableCellText/tableCellText.html +3 -0
  119. package/pg/tableCellText/tableCellText.ts +62 -0
  120. package/pg/tableColumn/README.md +3 -0
  121. package/pg/tableColumn/tableColumn.css +12 -0
  122. package/pg/tableColumn/tableColumn.html +1 -0
  123. package/pg/tableColumn/tableColumn.ts +29 -0
  124. package/pg/tableRow/README.md +3 -0
  125. package/pg/tableRow/tableRow.css +11 -0
  126. package/pg/tableRow/tableRow.html +1 -0
  127. package/pg/tableRow/tableRow.ts +77 -0
  128. package/pg/tabs/tabs.css +1 -1
  129. package/pg/tree/README.md +10 -4
  130. package/pg/tree/__examples__/basic/basic.html +1 -0
  131. package/pg/tree/__examples__/basic/basic.ts +6 -1
  132. package/pg/tree/tree.css +1 -0
  133. package/pg/treeItem/treeItem.css +3 -3
  134. package/favicon.svg +0 -20
  135. package/index.html +0 -321
  136. package/main.js +0 -2
  137. package/main.js.LICENSE.txt +0 -10
  138. package/pgAnnoy.js +0 -1
  139. package/pgApp.js +0 -1
  140. package/pgAvatar.js +0 -1
  141. package/pgButton.js +0 -1
  142. package/pgButtonGroup.js +0 -1
  143. package/pgButtonLink.js +0 -1
  144. package/pgButtonMenu.js +0 -1
  145. package/pgButtonToggle.js +0 -1
  146. package/pgCard.js +0 -1
  147. package/pgCardUser.js +0 -1
  148. package/pgColor.js +0 -1
  149. package/pgDatabase.js +0 -1
  150. package/pgDropdown.js +0 -1
  151. package/pgGrid.js +0 -1
  152. package/pgHeader.js +0 -1
  153. package/pgIcon.js +0 -1
  154. package/pgInputCheck.js +0 -1
  155. package/pgInputCheckList.js +0 -1
  156. package/pgInputFileLocal.js +0 -1
  157. package/pgInputHexRgb.js +0 -1
  158. package/pgInputPixelEditor.js +0 -1
  159. package/pgInputRange.js +0 -1
  160. package/pgInputSelect.js +0 -1
  161. package/pgInputText.js +0 -1
  162. package/pgInputTextIcon.js +0 -1
  163. package/pgInputUserSelect.js +0 -1
  164. package/pgListTag.js +0 -1
  165. package/pgMarkdown.js +0 -2
  166. package/pgMarkdown.js.LICENSE.txt +0 -10
  167. package/pgMenu.js +0 -1
  168. package/pgMenuDivider.js +0 -1
  169. package/pgMenuIcon.js +0 -1
  170. package/pgMenuItem.js +0 -1
  171. package/pgMenuItemIcon.js +0 -1
  172. package/pgModalAlert.js +0 -1
  173. package/pgModification.js +0 -1
  174. package/pgNav.js +0 -1
  175. package/pgOverlay.js +0 -1
  176. package/pgOverlayContextMenu.js +0 -1
  177. package/pgOverlayMenu.js +0 -1
  178. package/pgOverlaySelectMenu.js +0 -1
  179. package/pgOverlaySubMenu.js +0 -1
  180. package/pgPicker.js +0 -1
  181. package/pgPreview.js +0 -1
  182. package/pgScroll.js +0 -1
  183. package/pgSearch.js +0 -1
  184. package/pgTab.js +0 -1
  185. package/pgTabs.js +0 -1
  186. package/pgToast.js +0 -1
  187. package/pgToasts.js +0 -1
  188. package/pgTooltip.js +0 -1
  189. package/pgTree.js +0 -1
  190. package/pgTreeButtonIcon.js +0 -1
  191. package/pgTreeItem.js +0 -1
@@ -1,21 +1,28 @@
1
1
  :host {
2
2
  display: block;
3
- font-family: var(--pg-font-family);
3
+ font-family: var(--pg-font-family, system-ui);
4
4
  }
5
5
 
6
- [part="input"] {
6
+ [part=input] {
7
7
  border: 1px solid var(--pg-input-text-border-color, #453C4F);
8
8
  border-radius: 0.125rem;
9
- padding: calc(0.5rem - 1px) 0.75rem;
10
- font-family: var(--pg-font-family);
9
+ padding: var(--pg-input-text-padding, calc(0.5rem - 1px) 0.75rem);
10
+ font-family: var(--pg-input-text-font-family, var(--pg-font-family));
11
11
  font-size: 1rem;
12
12
  outline: none;
13
- width: calc(100% - 1.5rem - 2px);
13
+ field-sizing: content;
14
+ min-width: calc(100% - 0.5rem - 2px);
15
+ max-width: calc(var(--pg-input-text-max-width, 100%) - 0.5rem - 2px);
16
+ background-color: transparent;
14
17
  }
15
18
 
16
- [part="input"]:active {
19
+ [part=input]:read-only {
20
+ border-color: transparent;
21
+ }
22
+
23
+ [part=input]:active {
17
24
  box-shadow: 0 0 0 3px var(--pg-input-text-active-glow, rgb(79, 143, 249, 0.6));
18
25
  }
19
- [part="input"]:focus {
26
+ [part=input]:focus {
20
27
  box-shadow: 0 0 0 3px var(--pg-input-text-focus-glow, rgb(79, 143, 249, 0.5));
21
28
  }
@@ -12,6 +12,7 @@ export default class PgInputText extends HTMLElement {
12
12
  @Prop() name: string = '';
13
13
  @Prop() value: string = '';
14
14
  @Prop() placeholder: string = '';
15
+ @Prop() readOnly: boolean = false;
15
16
 
16
17
  @Part() $input: HTMLInputElement;
17
18
 
@@ -29,6 +30,9 @@ export default class PgInputText extends HTMLElement {
29
30
  if (changes.placeholder) {
30
31
  this.$input.placeholder = this.placeholder;
31
32
  }
33
+ if (changes.readOnly) {
34
+ this.$input.readOnly = this.readOnly;
35
+ }
32
36
  this.skipValue = false;
33
37
  }
34
38
 
@@ -56,4 +60,4 @@ export default class PgInputText extends HTMLElement {
56
60
  })
57
61
  );
58
62
  }
59
- }
63
+ }
@@ -0,0 +1,59 @@
1
+ # `<pg-json>`
2
+
3
+ The `pg-json` component renders json and allows values to be modified. The default data type rendering is below.
4
+
5
+ - `PgJsonArray`
6
+ - `PgJsonObject` - `null` is hardcoded
7
+ - `PgJsonString`
8
+ - `PgJsonBoolean`
9
+ - `PgJsonNumber`
10
+
11
+ ```typescript
12
+ import '@pictogrammers/components/pg/json';
13
+ import PgIcon from '@pictogrammers/components/pg/json';
14
+ ```
15
+
16
+ ```html
17
+ <pg-json part="json"></pg-json>
18
+ ```
19
+
20
+ | Attributes | Tested | Default | Description |
21
+ | ---------- | -------- | ------- | ----------- |
22
+ | value | | `{}` | Set json data |
23
+ | root | | `[]` | Root of object to render |
24
+ | schema | | `null` | JSON Schema |
25
+ | expand | | `0` | Default level to expand |
26
+ | limit | | `10` | Arrays max items "...{total - max} view more" |
27
+ | loadMore | | `10` | Amount to render after clicking load more |
28
+
29
+ For a root array type set `root: ['items']` and value `{ items: [] }`.
30
+
31
+ ## Event
32
+
33
+ ```typescript
34
+ this.$json.value = {
35
+ users: [{
36
+ name: 'Dipper Pines',
37
+ age: 12,
38
+ }]
39
+ }; // Array or Object
40
+ this.$json.addEventListener('change', (e: any) => {
41
+ const { parent, key, path, value } = e.detail;
42
+ if (value !== parent[key]) {
43
+ parent[key] = value;
44
+ }
45
+ });
46
+ ```
47
+
48
+ The `path` array gives the deep nesting for the record being modified.
49
+
50
+ ```typescript
51
+ // Modifying Dipper's name for instance
52
+ path = ['users', 0, 'name'];
53
+ ```
54
+
55
+ ## Schema
56
+
57
+ Not required if simply editing existing data. To allow complex editing add a defined schema object.
58
+
59
+ See https://json-schema.org for tutorials on writing your own schema.
@@ -0,0 +1,4 @@
1
+ <div class="example">
2
+ <pg-json part="json"></pg-json>
3
+ <pre part="output"></pre>
4
+ </div>
@@ -0,0 +1,31 @@
1
+ import { Component, Part, Prop } from '@pictogrammers/element';
2
+
3
+ import PgJson from '../../json';
4
+
5
+ import template from './basic.html';
6
+
7
+ @Component({
8
+ selector: 'x-pg-json-basic',
9
+ template
10
+ })
11
+ export default class XPgJsonBasic extends HTMLElement {
12
+ @Part() $json: PgJson;
13
+ @Part() $output: HTMLPreElement;
14
+
15
+ connectedCallback() {
16
+ this.$json.value = {
17
+ users: [{
18
+ name: 'Dipper Pines',
19
+ age: 12,
20
+ selected: false,
21
+ }]
22
+ }; // Array or Object
23
+ this.$json.addEventListener('change', (e: any) => {
24
+ const { parent, key, value } = e.detail;
25
+ if (value !== parent[key]) {
26
+ parent[key] = value;
27
+ }
28
+ this.$output.textContent = JSON.stringify(this.$json.value);
29
+ });
30
+ }
31
+ }
@@ -0,0 +1,9 @@
1
+ :host {
2
+ display: contents;
3
+ }
4
+
5
+ [part=container] {
6
+ --pg-json-font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
7
+ font-family: var(--pg-json-font-family);
8
+ user-select: none;
9
+ }
@@ -0,0 +1 @@
1
+ <div part="container"></div>
@@ -0,0 +1,124 @@
1
+ import { Component, Prop, Part } from '@pictogrammers/element';
2
+
3
+ import PgJsonArray from '../jsonArray/jsonArray';
4
+ import PgJsonObject from '../jsonObject/jsonObject';
5
+ import PgJsonString from '../jsonString/jsonString';
6
+ import PgJsonBoolean from '../jsonBoolean/jsonBoolean';
7
+ import PgJsonNumber from '../jsonNumber/jsonNumber';
8
+
9
+ import template from './json.html';
10
+ import style from './json.css';
11
+
12
+ function getType(value) {
13
+ if (typeof value === 'string') {
14
+ return PgJsonString;
15
+ }
16
+ if (typeof value === 'boolean') {
17
+ return PgJsonBoolean;
18
+ }
19
+ if (typeof value === 'number') {
20
+ return PgJsonNumber;
21
+ }
22
+ }
23
+
24
+ function unwrapObject(obj: any) {
25
+ return Object.keys(obj).map((key) => {
26
+ if (Array.isArray(obj[key])) {
27
+ return {
28
+ key,
29
+ value: unwrapArray(obj[key]),
30
+ type: PgJsonArray,
31
+ };
32
+ }
33
+ if (typeof obj[key] === 'object') {
34
+ return {
35
+ key,
36
+ value: unwrapObject(obj[key]),
37
+ type: PgJsonObject,
38
+ };
39
+ }
40
+ return {
41
+ key,
42
+ value: obj[key],
43
+ type: getType(obj[key]),
44
+ };
45
+ });
46
+ }
47
+
48
+ function unwrapArray(items: any) {
49
+ return items.map((item, i) => {
50
+ if (Array.isArray(item)) {
51
+ return {
52
+ key: i.toString(),
53
+ value: unwrapArray(item),
54
+ type: PgJsonArray,
55
+ };
56
+ }
57
+ if (typeof item === 'object') {
58
+ return {
59
+ key: i.toString(),
60
+ value: unwrapObject(item),
61
+ type: PgJsonObject,
62
+ };
63
+ }
64
+ return {
65
+ key: i.toString(),
66
+ value: item,
67
+ type: getType(item),
68
+ }
69
+ });
70
+ }
71
+
72
+ @Component({
73
+ selector: 'pg-json',
74
+ style,
75
+ template,
76
+ })
77
+ export default class PgJson extends HTMLElement {
78
+ @Prop() value: any = null;
79
+ @Prop() root = [];
80
+ @Prop() schema: any = null;
81
+
82
+ @Part() $container: HTMLElement;
83
+
84
+ render(changes) {
85
+ if (changes.value && this.value !== null) {
86
+ if (this.$container.children.length === 1) {
87
+ this.$container.children[0].remove();
88
+ }
89
+ if (typeof this.value === 'object') {
90
+ const $object = document.createElement('pg-json-object') as PgJsonObject;
91
+ $object.value = unwrapObject(this.value);
92
+ $object.addEventListener('update', this.handleUpdate.bind(this));
93
+ this.$container.appendChild($object);
94
+ } else if (Array.isArray(this.value)) {
95
+ const $array = document.createElement('pg-json-array') as PgJsonArray;
96
+ $array.value = unwrapArray(this.value);
97
+ $array.addEventListener('update', this.handleUpdate.bind(this));
98
+ this.$container.appendChild($array);
99
+ }
100
+ }
101
+ }
102
+
103
+ getParent(path: string[], parent) {
104
+ const key = path.pop();
105
+ if (key && (typeof parent[key] === 'object' || parent[key] instanceof Array)) {
106
+ return this.getParent(path, parent[key]);
107
+ }
108
+ return parent;
109
+ }
110
+
111
+ handleUpdate(e: any) {
112
+ const { path, key, value } = e.detail;
113
+ const parent = this.getParent(path, this.value);
114
+ this.dispatchEvent(
115
+ new CustomEvent('change', {
116
+ detail: {
117
+ parent,
118
+ key,
119
+ value,
120
+ }
121
+ })
122
+ )
123
+ }
124
+ }
@@ -0,0 +1,3 @@
1
+ # `<pg-json>`
2
+
3
+ The `PgJsonArray` is used in `pg-json`.
@@ -0,0 +1,15 @@
1
+ :host {
2
+ display: contents;
3
+ }
4
+
5
+ .hide {
6
+ display: none;
7
+ }
8
+
9
+ [part=items] {
10
+ padding-left: 1rem;
11
+ }
12
+
13
+ [part=start] {
14
+ display: flex;
15
+ }
@@ -0,0 +1,7 @@
1
+ <div part="start">
2
+ <div part="key"></div>
3
+ <div part="seperator">:&nbsp;</div>
4
+ <div part="startLabel">[</div>
5
+ </div>
6
+ <div part="items"></div>
7
+ <div part="endLabel">]</div>
@@ -0,0 +1,55 @@
1
+ import { Component, Prop, Part, forEach } from '@pictogrammers/element';
2
+
3
+ import PgJsonObject from '../jsonObject/jsonObject';
4
+ import PgJsonString from '../jsonString/jsonString';
5
+ import PgJsonBoolean from '../jsonBoolean/jsonBoolean';
6
+ import PgJsonNumber from '../jsonNumber/jsonNumber';
7
+
8
+ import template from './jsonArray.html';
9
+ import style from './jsonArray.css';
10
+
11
+ @Component({
12
+ selector: 'pg-json-array',
13
+ style,
14
+ template,
15
+ })
16
+ export default class PgJsonArray extends HTMLElement {
17
+ @Prop() key: string = '';
18
+ @Prop() value: any[] = [];
19
+ @Prop() expanded: boolean = false;
20
+
21
+ @Part() $key: HTMLDivElement;
22
+ @Part() $seperator: HTMLDivElement;
23
+ @Part() $items: HTMLDivElement;
24
+
25
+ connectedCallback() {
26
+ forEach({
27
+ container: this.$items,
28
+ items: this.value,
29
+ type: (item) => item.type,
30
+ create: ($item, item) => {
31
+ $item.addEventListener('update', (e: any) => {
32
+ const { path, key, value } = e.detail;
33
+ this.key && path.push(this.key);
34
+ this.dispatchEvent(
35
+ new CustomEvent('update', {
36
+ detail: {
37
+ path,
38
+ key,
39
+ value,
40
+ }
41
+ })
42
+ );
43
+ });
44
+ },
45
+ });
46
+ }
47
+
48
+ render(changes) {
49
+ if (changes.key) {
50
+ this.$key.classList.toggle('hide', this.key === '');
51
+ this.$seperator.classList.toggle('hide', this.key === '');
52
+ this.$key.textContent = this.key;
53
+ }
54
+ }
55
+ }
@@ -0,0 +1,3 @@
1
+ # `PgJsonBoolean`
2
+
3
+ The `PgJsonBoolean` is used in `pg-json`.
@@ -0,0 +1,27 @@
1
+ :host {
2
+ display: flex;
3
+ }
4
+
5
+ [part=key],
6
+ [part=seperator] {
7
+ display: inline-flex;
8
+ align-items: center;
9
+ }
10
+
11
+ [part=value] {
12
+ margin: 0 -0.25rem;
13
+ background-color: transparent;
14
+ border: 0;
15
+ font-size: 1rem;
16
+ padding: 0.125rem 0.25rem;
17
+ vertical-align: middle;
18
+ font-family: inherit;
19
+ z-index: 1;
20
+ position: relative;
21
+ outline: 0;
22
+ border-radius: 0.125rem;
23
+ }
24
+
25
+ [part=value]:focus-visible {
26
+ box-shadow: 0 0 0 3px var(--pg-input-text-focus-glow, rgb(79, 143, 249, 0.5));
27
+ }
@@ -0,0 +1,5 @@
1
+ <div part="key"></div>
2
+ <div part="seperator">:&nbsp;</div>
3
+ <div part="container">
4
+ <button part="value"></button>
5
+ </div>
@@ -0,0 +1,69 @@
1
+ import { Component, Prop, Part } from '@pictogrammers/element';
2
+
3
+ import PgOverlaySelectMenu from '../overlaySelectMenu/overlaySelectMenu';
4
+
5
+ import template from './jsonBoolean.html';
6
+ import style from './jsonBoolean.css';
7
+
8
+ @Component({
9
+ selector: 'pg-json-boolean',
10
+ style,
11
+ template,
12
+ })
13
+ export default class PgJsonBoolean extends HTMLElement {
14
+ @Prop() key: string = '';
15
+ @Prop() value: boolean = false;
16
+
17
+ @Part() $key: HTMLDivElement;
18
+ @Part() $value: HTMLButtonElement;
19
+
20
+ connectedCallback() {
21
+ this.$value.addEventListener('click', this.#handleClick.bind(this));
22
+ // this.$value.value = e.detail.value;
23
+ // this.dispatchEvent(
24
+ // new CustomEvent('update', {
25
+ // detail: {
26
+ // path: [this.key],
27
+ // value: e.detail.value,
28
+ // }
29
+ // })
30
+ // );
31
+ }
32
+
33
+ render(changes) {
34
+ if (changes.key) {
35
+ this.$key.textContent = this.key;
36
+ }
37
+ if (changes.value) {
38
+ this.$value.textContent = this.value ? 'true' : 'false';
39
+ }
40
+ }
41
+
42
+ options = [
43
+ { label: 'true', value: 'true' },
44
+ { label: 'false', value: 'false' },
45
+ ];
46
+
47
+ #menuOpen = false;
48
+ async #handleClick() {
49
+ if (this.#menuOpen) { return; }
50
+ this.#menuOpen = true;
51
+ const result = await PgOverlaySelectMenu.open({
52
+ source: this.$value,
53
+ value: this.options.find(x => x.value === `${this.value}`) ?? 'false',
54
+ items: this.options,
55
+ });
56
+ if (result !== undefined) {
57
+ this.dispatchEvent(new CustomEvent('update', {
58
+ detail: {
59
+ path: [this.key],
60
+ key: this.key,
61
+ value: result.value === 'true'
62
+ }
63
+ }));
64
+ this.$value.textContent = result.label;
65
+ this.value = result.value === 'true';
66
+ }
67
+ this.#menuOpen = false;
68
+ }
69
+ }
@@ -0,0 +1,3 @@
1
+ # `<pg-json>`
2
+
3
+ The `PgJsonArray` is used in `pg-json`.
@@ -0,0 +1,21 @@
1
+ :host {
2
+ display: flex;
3
+ }
4
+
5
+ [part=key],
6
+ [part=seperator] {
7
+ display: inline-flex;
8
+ align-items: center;
9
+ }
10
+
11
+ [part=value] {
12
+ user-select: text;
13
+ --pg-input-text-padding: 0 0.25rem;
14
+ --pg-input-text-border-color: transparent;
15
+ --pg-input-number-font-family: var(--pg-json-font-family);
16
+ display: inline-flex;
17
+ vertical-align: middle;
18
+ margin: 0 -0.25rem;
19
+ z-index: 1;
20
+ position: relative;
21
+ }
@@ -0,0 +1,5 @@
1
+ <div part="key"></div>
2
+ <div part="seperator">:&nbsp;</div>
3
+ <div part="container">
4
+ <pg-input-number part="value"></pg-input-number>
5
+ </div>
@@ -0,0 +1,42 @@
1
+ import { Component, Prop, Part } from '@pictogrammers/element';
2
+
3
+ import PgInputNumber from '../inputNumber/inputNumber';
4
+
5
+ import template from './jsonNumber.html';
6
+ import style from './jsonNumber.css';
7
+
8
+ @Component({
9
+ selector: 'pg-json-number',
10
+ style,
11
+ template,
12
+ })
13
+ export default class PgJsonNumber extends HTMLElement {
14
+ @Prop() key: string = '';
15
+ @Prop() value: number = 0;
16
+
17
+ @Part() $key: HTMLDivElement;
18
+ @Part() $value: PgInputNumber;
19
+
20
+ connectedCallback() {
21
+ this.$value.addEventListener('input', (e: any) => {
22
+ this.dispatchEvent(
23
+ new CustomEvent('update', {
24
+ detail: {
25
+ path: [this.key],
26
+ key: this.key,
27
+ value: Number.parseInt(e.detail.value, 10),
28
+ }
29
+ })
30
+ );
31
+ });
32
+ }
33
+
34
+ render(changes) {
35
+ if (changes.key) {
36
+ this.$key.textContent = this.key;
37
+ }
38
+ if (changes.value) {
39
+ this.$value.value = `${this.value}`;
40
+ }
41
+ }
42
+ }
@@ -0,0 +1,3 @@
1
+ # `<pg-json>`
2
+
3
+ The `PgJsonArray` is used in `pg-json`.
@@ -0,0 +1,11 @@
1
+ :host {
2
+ display: contents;
3
+ }
4
+
5
+ .hide {
6
+ display: none;
7
+ }
8
+
9
+ [part=items] {
10
+ padding-left: 1rem;
11
+ }
@@ -0,0 +1,5 @@
1
+ <div part="key"></div>
2
+ <div part="seperator">:</div>
3
+ <div part="startLabel">{</div>
4
+ <div part="items"></div>
5
+ <div part="endLabel">}</div>
@@ -0,0 +1,55 @@
1
+ import { Component, Prop, Part, forEach } from '@pictogrammers/element';
2
+
3
+ import PgJsonArray from '../jsonArray/jsonArray';
4
+ import PgJsonString from '../jsonString/jsonString';
5
+ import PgJsonBoolean from '../jsonBoolean/jsonBoolean';
6
+ import PgJsonNumber from '../jsonNumber/jsonNumber';
7
+
8
+ import template from './jsonObject.html';
9
+ import style from './jsonObject.css';
10
+
11
+ @Component({
12
+ selector: 'pg-json-object',
13
+ style,
14
+ template,
15
+ })
16
+ export default class PgJsonObject extends HTMLElement {
17
+ @Prop() key: string = '';
18
+ @Prop() value: any[] = [];
19
+ @Prop() expanded: boolean = false;
20
+
21
+ @Part() $key: HTMLDivElement;
22
+ @Part() $seperator: HTMLDivElement;
23
+ @Part() $items: HTMLDivElement;
24
+
25
+ connectedCallback() {
26
+ forEach({
27
+ container: this.$items,
28
+ items: this.value,
29
+ type: (item) => item.type,
30
+ create: ($item, item) => {
31
+ $item.addEventListener('update', (e: any) => {
32
+ const { path, key, value } = e.detail;
33
+ this.key && path.push(this.key);
34
+ this.dispatchEvent(
35
+ new CustomEvent('update', {
36
+ detail: {
37
+ path,
38
+ key,
39
+ value,
40
+ }
41
+ })
42
+ );
43
+ });
44
+ },
45
+ });
46
+ }
47
+
48
+ render(changes) {
49
+ if (changes.key) {
50
+ this.$key.classList.toggle('hide', this.key === '' || !isNaN(this.key as any));
51
+ this.$seperator.classList.toggle('hide', this.key === '' || !isNaN(this.key as any));
52
+ this.$key.textContent = this.key;
53
+ }
54
+ }
55
+ }
@@ -0,0 +1,3 @@
1
+ # `<pg-json>`
2
+
3
+ The `PgJsonArray` is used in `pg-json`.
@@ -0,0 +1,21 @@
1
+ :host {
2
+ display: flex;
3
+ }
4
+
5
+ [part=key],
6
+ [part=seperator] {
7
+ display: inline-flex;
8
+ align-items: center;
9
+ }
10
+
11
+ [part=value] {
12
+ user-select: text;
13
+ --pg-input-text-padding: 0 0.25rem;
14
+ --pg-input-text-border-color: transparent;
15
+ --pg-input-text-font-family: var(--pg-json-font-family);
16
+ display: inline-flex;
17
+ vertical-align: middle;
18
+ margin: 0 -0.25rem;
19
+ z-index: 1;
20
+ position: relative;
21
+ }
@@ -0,0 +1,5 @@
1
+ <div part="key"></div>
2
+ <div part="seperator">:&nbsp;</div>
3
+ <div part="container">
4
+ <span>&quot;</span><pg-input-text part="value"></pg-input-text><span>&quot;</span>
5
+ </div>