@pageboard/html 0.12.3 → 0.12.5

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.
@@ -81,9 +81,127 @@ exports.strike = {
81
81
  html: '<s></s>'
82
82
  };
83
83
 
84
- exports.caps = {
84
+ exports.style = {
85
+ priority: 99,
86
+ title: "Style",
87
+ icon: '<i class="paint brush icon"></i>',
88
+ contents: "text*",
89
+ inline: true,
90
+ inplace: true,
91
+ group: "inline nolink",
92
+ tag: 'span.style',
93
+ properties: {
94
+ size: {
95
+ title: 'Size',
96
+ default: null,
97
+ anyOf: [{
98
+ const: null,
99
+ title: 'Default',
100
+ icon: '<span class="icon">∅</span>'
101
+ }, {
102
+ const: 'small',
103
+ title: 'Small',
104
+ icon: '<span class="icon char" style="font-size:0.6em">aA</span>'
105
+ }, {
106
+ const: 'base',
107
+ title: 'Base',
108
+ icon: '<span class="icon char" style="font-size:0.8em">aA</span>'
109
+ }, {
110
+ const: 'large',
111
+ title: 'Large',
112
+ icon: '<span class="icon char" style="font-size:1.2em">aA</span>'
113
+ }, {
114
+ const: 'extra',
115
+ title: 'Extra',
116
+ icon: '<span class="icon char" style="font-size:1.6em">aA</span>'
117
+ }]
118
+ },
119
+ transform: {
120
+ title: 'Transform',
121
+ default: null,
122
+ anyOf: [{
123
+ const: null,
124
+ title: 'Default',
125
+ icon: '<span class="icon">∅</span>'
126
+ }, {
127
+ const: "uppercase",
128
+ title: "upper",
129
+ icon: '<span class="icon">AB</span>'
130
+ }, {
131
+ const: "lowercase",
132
+ title: "lower",
133
+ icon: '<span class="icon">ab</span>'
134
+ }, {
135
+ const: "capitalize",
136
+ title: "all caps",
137
+ icon: '<span class="icon" style="text-transform:capitalize">Ab</span>'
138
+ }, {
139
+ const: "smallcaps",
140
+ title: "small caps",
141
+ icon: '<span class="icon" style="font-variant:small-caps">Ab</span>'
142
+ }]
143
+ },
144
+ color: {
145
+ title: 'Color',
146
+ default: null,
147
+ anyOf: [{
148
+ const: null,
149
+ title: 'Default',
150
+ icon: '<span class="icon">∅</span>'
151
+ }, {
152
+ const: "white",
153
+ title: "White",
154
+ icon: '<i class="icon color" style="color:white">W</i>'
155
+ }, {
156
+ const: "black",
157
+ title: "Black",
158
+ icon: '<i class="icon color" style="color:black">B</i>'
159
+ }, {
160
+ const: "red",
161
+ title: "Red",
162
+ icon: '<i class="icon color" style="color:red">R</i>'
163
+ }, {
164
+ const: "orange",
165
+ title: "Orange",
166
+ icon: '<i class="icon color" style="color:orange">O</i>'
167
+ }, {
168
+ const: "yellow",
169
+ title: "Yellow",
170
+ icon: '<i class="icon color" style="color:yellow">Y</i>'
171
+ }, {
172
+ const: "green",
173
+ title: "Green",
174
+ icon: '<i class="icon color" style="color:green">G</i>'
175
+ }, {
176
+ const: "blue",
177
+ title: "Blue",
178
+ icon: '<i class="icon color" style="color:blue">B</i>'
179
+ }, {
180
+ const: "purple",
181
+ title: "Purple",
182
+ icon: '<i class="icon color" style="color:purple">P</i>'
183
+ }]
184
+ }
185
+ },
186
+ parse: function(dom) {
187
+ const data = {};
188
+ for (const [key, schema] of Object.entries(this.properties)) {
189
+ for (const item of schema.anyOf) {
190
+ if (item.const && dom.classList.contains(item.const)) {
191
+ data[key] = item.const;
192
+ }
193
+ }
194
+ }
195
+ return data;
196
+ },
197
+ html: '<span class="style [size] [transform] [color]"></span>',
198
+ stylesheets: [
199
+ '../ui/inlines.css'
200
+ ]
201
+ };
202
+
203
+ exports.caps = { // deprecated
85
204
  priority: 108,
86
- title: "Capitalization",
87
205
  icon: '<span class="icon">A<span style="font-variant: small-caps;">a</span></span>',
88
206
  contents: "text*",
89
207
  inline: true,
@@ -92,7 +210,7 @@ exports.caps = {
92
210
  parse: function(dom) {
93
211
  return { transform: dom.className };
94
212
  },
95
- tag: 'span.uppercase,span.lowercase,span.capitalize,span.smallcaps',
213
+ tag: 'span.uppercase:not(.style),span.lowercase:not(.style),span.capitalize:not(.style),span.smallcaps:not(.style)',
96
214
  properties: {
97
215
  transform: {
98
216
  title: 'Transform',
@@ -119,14 +237,9 @@ exports.caps = {
119
237
  html: '<span class="[transform]"></span>'
120
238
  };
121
239
 
122
- exports.color = {
240
+ exports.color = { // deprecated
123
241
  priority: 109,
124
- title: "Color",
125
- icon: `<i class="icon" style="background-image:
126
- linear-gradient(
127
- to right,
128
- red, orange, yellow, green, blue, purple
129
- );"></i>`,
242
+ icon: '<span class="icon">C</span>',
130
243
  properties: {
131
244
  color: {
132
245
  default: "",
package/elements/time.js CHANGED
@@ -171,6 +171,7 @@ exports.time = {
171
171
  format
172
172
  };
173
173
  },
174
- html: `<time datetime="[datetime|now|isoDate]" data-format="[format|values|join:%3A]" data-timezone="[timezone]" is="element-time"></time>`,
174
+ tag: 'time',
175
+ html: `<time datetime="[datetime|or:now|date:iso]" data-format="[format|as:values|join:%3A]" data-timezone="[timezone]" is="element-time"></time>`,
175
176
  scripts: ['../ui/time.js']
176
177
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pageboard/html",
3
- "version": "0.12.3",
3
+ "version": "0.12.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -54,8 +54,8 @@ class HTMLElementFieldsetList extends Page.Element {
54
54
  for (const node of inputs) {
55
55
  keys.add(node.name);
56
56
  }
57
- const splits = Array.from(keys).map(name => name.split('.'));
58
- const coms = [];
57
+ const splits = Array.from(keys).map(name => this.#parts(name));
58
+ const prefix = [];
59
59
  let pos = 0, com = null;
60
60
  while (splits.length && splits.every(list => {
61
61
  if (com == null) {
@@ -69,16 +69,16 @@ class HTMLElementFieldsetList extends Page.Element {
69
69
  return list[pos] == com;
70
70
  }
71
71
  })) {
72
- coms.push(com);
72
+ prefix.push(com);
73
73
  com = null;
74
74
  pos++;
75
75
  }
76
- if (coms.length) coms.push('');
77
- const prefix = coms.join('.');
78
76
  this.#prefix = prefix;
79
77
  const model = {};
80
78
  for (const key of keys) {
81
- if (key.startsWith(prefix)) model[key.substring(prefix.length)] = null;
79
+ if (this.#prefixed(key)) {
80
+ model[this.#parts(key).slice(prefix.length).join('.')] = null;
81
+ }
82
82
  }
83
83
  this.#model = model;
84
84
  }
@@ -109,6 +109,22 @@ class HTMLElementFieldsetList extends Page.Element {
109
109
  return `[block-type="fieldlist_button"][value="${name}"]`;
110
110
  }
111
111
 
112
+ #prefixed(key, p = this.#prefix) {
113
+ const parts = this.#parts(key);
114
+ for (let i = 0; i < p.length; i++) {
115
+ if (parts[i] != p[i]) return false;
116
+ }
117
+ return true;
118
+ }
119
+
120
+ #incrementkey(index, name) {
121
+ if (!this.#prefixed(name)) return null;
122
+ const parts = this.#prefix.slice();
123
+ parts.push(index);
124
+ parts.push(...this.#parts(name).slice(this.#prefix.length));
125
+ return parts.join('.');
126
+ }
127
+
112
128
  #resize(size, scope) {
113
129
  if (scope.$write) return;
114
130
  const len = Math.max(Number(this.dataset.size) || 0, size);
@@ -119,25 +135,17 @@ class HTMLElementFieldsetList extends Page.Element {
119
135
  return { index: i };
120
136
  });
121
137
  const inputs = tpl.querySelectorAll('[name]');
122
- const prefix = this.#prefix;
123
138
  for (const node of inputs) {
124
- if (node.name.startsWith(prefix)) {
125
- node.name = `${prefix}[fielditem.index].${node.name.substring(prefix.length)}`;
126
- if (node.id?.startsWith('for-' + prefix)) {
127
- node.id = `for-${prefix}[fielditem.index].${node.id.substring(4 + prefix.length)}`;
128
- }
139
+ const name = this.#incrementkey('[fielditem.index]', node.name);
140
+ if (name != null) {
141
+ node.name = name;
129
142
  }
130
143
  }
131
144
  const conditionalFieldsets = tpl.querySelectorAll('[is="element-fieldset"]');
132
145
  for (const node of conditionalFieldsets) {
133
- if (node.dataset.name?.startsWith(prefix)) {
134
- node.dataset.name = `${prefix}[fielditem.index].${node.dataset.name.substring(prefix.length)}`;
135
- }
136
- }
137
- const labels = tpl.querySelectorAll('label[for]');
138
- for (const node of labels) {
139
- if (node.htmlFor?.startsWith('for-' + prefix)) {
140
- node.htmlFor = `for-${prefix}[fielditem.index].${node.htmlFor.substring(4 + prefix.length)}`;
146
+ const name = this.#incrementkey('[fielditem.index]', node.dataset.name);
147
+ if (name != null) {
148
+ node.dataset.name = name;
141
149
  }
142
150
  }
143
151
 
@@ -159,7 +167,7 @@ class HTMLElementFieldsetList extends Page.Element {
159
167
  {
160
168
  const hidden = tpl.ownerDocument.createElement('input');
161
169
  hidden.type = "hidden";
162
- hidden.name = prefix.slice(0, -1);
170
+ hidden.name = this.#prefix.join('.');
163
171
  tpl.appendChild(hidden);
164
172
  }
165
173
  }
@@ -177,13 +185,16 @@ class HTMLElementFieldsetList extends Page.Element {
177
185
  });
178
186
  }
179
187
 
188
+ #parts(key) {
189
+ return key ? key.split(".") : [];
190
+ }
191
+
180
192
  #listFromValues(values) {
181
193
  const list = [];
182
- const prefix = this.#prefix;
183
194
  // just unflatten the array
184
195
  for (const [key, val] of Object.entries(values)) {
185
- if (!key.startsWith(prefix)) continue;
186
- const parts = key.slice(prefix.length).split(".");
196
+ if (!this.#prefixed(key)) continue;
197
+ const parts = this.#parts(key).slice(this.#prefix.length);
187
198
  const index = Number(parts.shift());
188
199
  if (!Number.isInteger(index)) continue;
189
200
  delete values[key];
@@ -195,11 +206,13 @@ class HTMLElementFieldsetList extends Page.Element {
195
206
  }
196
207
 
197
208
  #listToValues(values, list) {
198
- const prefix = this.#prefix;
199
209
  for (let i = 0; i < list.length; i++) {
200
210
  const obj = list[i];
201
211
  for (const [key, val] of Object.entries(obj)) {
202
- values[`${prefix}${i}.${key}`] = val;
212
+ const parts = this.#prefix.slice();
213
+ parts.push(i);
214
+ parts.push(...this.#parts(key));
215
+ values[parts.join('.')] = val;
203
216
  }
204
217
  }
205
218
  }
@@ -261,9 +274,10 @@ class HTMLElementFieldsetList extends Page.Element {
261
274
  }
262
275
 
263
276
  #parseName(name) {
264
- const prefix = this.prefix;
265
- if (!name?.startsWith(prefix)) return { index: -1 };
266
- const parts = name.substring(prefix.length).split('.');
277
+ if (!this.#prefixed(name)) {
278
+ return { index: -1 };
279
+ }
280
+ const parts = this.#parts(name).slice(this.#prefix.length);
267
281
  const index = Number(parts.shift());
268
282
  if (!Number.isInteger(index)) return { index: -1 };
269
283
  return { index, sub: parts.join('.') };
package/ui/fieldset.js CHANGED
@@ -19,14 +19,8 @@ class HTMLElementFieldSet extends Page.create(HTMLFieldSetElement) {
19
19
  this.fill(null, state.scope);
20
20
  state.finish(() => this.fill(null, state.scope));
21
21
  }
22
- setup() {
23
- this.form?.addEventListener('change', this);
24
- }
25
- close() {
26
- this.form?.removeEventListener('change', this);
27
- }
28
- handleEvent(e, state) {
29
- if (e.type == "change") {
22
+ handleAllChange(e, state) {
23
+ if (this.form.contains(e.target)) {
30
24
  this.fill(null, state.scope);
31
25
  }
32
26
  }
package/ui/inlines.css ADDED
@@ -0,0 +1,51 @@
1
+ span.lighter {
2
+ font-weight:lighter;
3
+ }
4
+ span.capitalize {
5
+ text-transform:capitalize;
6
+ }
7
+ span.lowercase {
8
+ text-transform:lowercase;
9
+ }
10
+ span.uppercase {
11
+ text-transform:uppercase;
12
+ }
13
+ span.smallcaps {
14
+ font-variant:small-caps;
15
+ }
16
+ span.black {
17
+ color: black;
18
+ }
19
+ span.white {
20
+ color: white;
21
+ }
22
+ span.red {
23
+ color: red;
24
+ }
25
+ span.orange {
26
+ color: orange;
27
+ }
28
+ span.yellow {
29
+ color: yellow;
30
+ }
31
+ span.green {
32
+ color: green;
33
+ }
34
+ span.blue {
35
+ color: blue;
36
+ }
37
+ span.purple {
38
+ color: purple;
39
+ }
40
+ span.small {
41
+ font-size: 0.8em;
42
+ }
43
+ span.base {
44
+ font-size: 1.2em;
45
+ }
46
+ span.large {
47
+ font-size: 1.6em;
48
+ }
49
+ span.extra {
50
+ font-size: 2em;
51
+ }
package/ui/select.js CHANGED
@@ -169,7 +169,7 @@ class HTMLElementSelect extends Page.Element {
169
169
  }
170
170
 
171
171
  patch(state) {
172
- if (this.state.scope.$write) return;
172
+ if (state.scope.$write) return;
173
173
  if (this.children.length == 1) this.build(state);
174
174
 
175
175
  state.finish(() => {
package/ui/site.css CHANGED
@@ -106,45 +106,7 @@ p:last-child {
106
106
  text-align:justify;
107
107
  }
108
108
 
109
- span.lighter {
110
- font-weight:lighter;
111
- }
112
- span.capitalize {
113
- text-transform:capitalize;
114
- }
115
- span.lowercase {
116
- text-transform:lowercase;
117
- }
118
- span.uppercase {
119
- text-transform:uppercase;
120
- }
121
- span.smallcaps {
122
- font-variant:small-caps;
123
- }
124
- span.black {
125
- color: black;
126
- }
127
- span.white {
128
- color: white;
129
- }
130
- span.red {
131
- color: red;
132
- }
133
- span.orange {
134
- color: orange;
135
- }
136
- span.yellow {
137
- color: yellow;
138
- }
139
- span.green {
140
- color: green;
141
- }
142
- span.blue {
143
- color: blue;
144
- }
145
- span.purple {
146
- color: purple;
147
- }
109
+
148
110
 
149
111
  /*-------------------
150
112
  Links
package/ui/tab.css CHANGED
@@ -1,5 +1,6 @@
1
1
  element-tabs {
2
2
  display:block;
3
+ width: 100%;
3
4
  }
4
5
  .ui.tab.segment:not(.active) {
5
6
  display: none;
package/ui/tab.js CHANGED
@@ -11,11 +11,11 @@ class HTMLElementTabs extends Page.Element {
11
11
  }
12
12
  patch(state) {
13
13
  const pos = this.options.index;
14
- const id = this.id;
14
+ const key = `${this.id}.index`;
15
+ state.vars[key] = true;
15
16
 
16
17
  this.items.children.forEach((item, i) => {
17
18
  const query = { ...state.query };
18
- const key = `${id}.index`;
19
19
  if (i == 0) delete query[key];
20
20
  else query[key] = i;
21
21
  item.setAttribute('href', Page.format({
package/ui/time.js CHANGED
@@ -6,7 +6,7 @@ class HTMLElementTime extends Page.create(HTMLTimeElement) {
6
6
  };
7
7
 
8
8
  patch(state) {
9
- this.textContent = `[stamp|formatDate:[fmt]:[tz]]`.fuse({
9
+ this.textContent = `[stamp|or:now|date:[fmt]:[tz]]`.fuse({
10
10
  stamp: this.dateTime,
11
11
  fmt: this.dataset.format,
12
12
  tz: this.dataset.timezone