@oods/components-vue 0.4.0 → 0.4.1

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 CHANGED
@@ -34,4 +34,4 @@ Use matching versions of the OODS packages. These packages are separate from the
34
34
 
35
35
  ## License
36
36
 
37
- Apache License 2.0. See [LICENSE](https://cdn.jsdelivr.net/npm/@oods/components-vue@0.4.0/LICENSE) and [NOTICE](https://cdn.jsdelivr.net/npm/@oods/components-vue@0.4.0/NOTICE). Generated output belongs to its user; installed package dependencies retain their own licenses.
37
+ Apache License 2.0. See [LICENSE](https://cdn.jsdelivr.net/npm/@oods/components-vue@0.4.1/LICENSE) and [NOTICE](https://cdn.jsdelivr.net/npm/@oods/components-vue@0.4.1/NOTICE). Generated output belongs to its user; installed package dependencies retain their own licenses.
package/dist/index.cjs CHANGED
@@ -187,6 +187,31 @@ var Button = vue.defineComponent({
187
187
  }
188
188
  });
189
189
  var canShowModal = () => typeof HTMLDialogElement !== "undefined" && typeof HTMLDialogElement.prototype.showModal === "function";
190
+ var pageLocks = 0;
191
+ var pageStyle;
192
+ function lockPageScroll() {
193
+ const page = document.documentElement;
194
+ if (pageLocks++ === 0) {
195
+ const scrollbar = window.innerWidth - page.clientWidth;
196
+ pageStyle = { overflow: page.style.overflow, paddingRight: page.style.paddingRight };
197
+ if (scrollbar > 0) page.style.paddingRight = `${parseFloat(getComputedStyle(page).paddingRight) + scrollbar}px`;
198
+ page.style.overflow = "hidden";
199
+ }
200
+ let held = true;
201
+ return () => {
202
+ if (!held) return;
203
+ held = false;
204
+ if (--pageLocks === 0 && pageStyle) {
205
+ page.style.overflow = pageStyle.overflow;
206
+ page.style.paddingRight = pageStyle.paddingRight;
207
+ pageStyle = void 0;
208
+ }
209
+ };
210
+ }
211
+ var outsideBox = (event, dialog) => {
212
+ const box = dialog.getBoundingClientRect();
213
+ return event.clientX < box.left || event.clientX > box.right || event.clientY < box.top || event.clientY > box.bottom;
214
+ };
190
215
  var Dialog = vue.defineComponent({
191
216
  name: "OodsDialog",
192
217
  props: {
@@ -208,15 +233,24 @@ var Dialog = vue.defineComponent({
208
233
  const element = vue.ref(null);
209
234
  const mounted = vue.ref(false);
210
235
  const managed = vue.computed(() => props.modal && mounted.value && canShowModal());
236
+ let unlockScroll;
237
+ let pressedBackdrop = false;
238
+ const releaseScroll = () => {
239
+ unlockScroll?.();
240
+ unlockScroll = void 0;
241
+ };
211
242
  const sync = () => {
212
243
  const dialog = element.value;
213
244
  if (!dialog || !managed.value) return;
214
- if (props.open && !dialog.open) dialog.showModal();
215
- else if (!props.open && dialog.open) dialog.close();
245
+ if (props.open && !dialog.open) {
246
+ dialog.showModal();
247
+ unlockScroll ??= lockPageScroll();
248
+ } else if (!props.open && dialog.open) dialog.close();
216
249
  };
217
250
  vue.onMounted(() => {
218
251
  mounted.value = true;
219
252
  });
253
+ vue.onBeforeUnmount(releaseScroll);
220
254
  vue.watch([() => props.open, managed], sync, { flush: "post" });
221
255
  const requestClose = (event) => {
222
256
  event.preventDefault();
@@ -239,10 +273,23 @@ var Dialog = vue.defineComponent({
239
273
  if (event.key === "Escape" && !event.defaultPrevented) requestClose(event);
240
274
  },
241
275
  onCancel: requestClose,
242
- // The browser closed it (a close request it would not let be cancelled) while open is still true. A close event
243
- // from moving a mounted dialog into the top layer finds it open again, and is not reported.
276
+ // A close event from moving a mounted dialog into the top layer finds it open again, and is not reported. Any other
277
+ // close releases the page; when the browser closed it (a close request it would not let be cancelled) while open is
278
+ // still true, it is reported.
244
279
  onClose: () => {
245
- if (props.open && !element.value?.open) emit("close");
280
+ if (element.value?.open) return;
281
+ releaseScroll();
282
+ if (props.open) emit("close");
283
+ },
284
+ onMousedown: (event) => {
285
+ pressedBackdrop = managed.value && event.target === event.currentTarget && outsideBox(event, event.currentTarget);
286
+ },
287
+ // s223-m02 (#2527 ruling 13b): a click on the backdrop emits close, as the close control does. A press that began
288
+ // inside the dialog (text selected and dragged out) is not a backdrop click.
289
+ onClick: (event) => {
290
+ const backdrop = pressedBackdrop && event.target === event.currentTarget && outsideBox(event, event.currentTarget);
291
+ pressedBackdrop = false;
292
+ if (backdrop) emit("close");
246
293
  }
247
294
  }, [
248
295
  vue.h("div", { class: "oods-dialog__header" }, [
@@ -805,12 +852,15 @@ function createBadgeFamily(options) {
805
852
  };
806
853
  for (const key of options.extraProps) props[key] = String;
807
854
  for (const key of options.booleanProps ?? []) props[key] = { type: [String, Boolean], default: void 0 };
855
+ if (options.booleanProps) props.hideWhenFalse = { type: [Boolean, String], default: void 0 };
808
856
  return vue.defineComponent({
809
857
  name: `Oods${options.component}`,
810
858
  props,
811
859
  setup(componentProps, { slots }) {
812
860
  return () => {
813
861
  const record = componentProps;
862
+ const flag = options.booleanProps?.map((key) => record[key]).find((value) => typeof value === "boolean");
863
+ if (record.hideWhenFalse === true && flag === false) return null;
814
864
  const content = authoredContent(slots.default?.());
815
865
  const scalar = scalarContent(content);
816
866
  const read = (key) => typeof record[key] === "boolean" && options.booleanProps?.includes(key) ? String(record[key]) : record[key];
@@ -1437,12 +1487,13 @@ var TagSummary = vue.defineComponent({
1437
1487
  });
1438
1488
  var OwnershipMeta = vue.defineComponent({
1439
1489
  name: "OodsOwnershipMeta",
1440
- props: { title: String, label: String, heading: String, name: String, ownerType: String, owner_type: String, role: String, ownershipRole: String },
1490
+ props: { title: String, label: String, heading: String, name: String, ownerType: String, owner_type: String, role: String, ownershipRole: String, ownerLabel: String },
1441
1491
  setup(props, { slots }) {
1442
1492
  return () => {
1443
1493
  const content = authoredContent(slots.default?.());
1444
1494
  const terms = [["Owner Type", firstScalar(props.ownerType, props.owner_type)], ["Role", firstScalar(props.role, props.ownershipRole)]].filter((entry) => entry[1] !== void 0);
1445
- return vue.h("div", { class: "oods-ownership-meta", "data-oods-component": "OwnershipMeta", "data-meta-type": "ownership" }, content.length ? content : [
1495
+ const phrase = props.ownerLabel !== void 0 ? componentContracts.ownershipPhrase(props.ownerLabel, firstScalar(props.ownerType, props.owner_type), firstScalar(props.role, props.ownershipRole)) : void 0;
1496
+ return vue.h("div", { class: "oods-ownership-meta", "data-oods-component": "OwnershipMeta", "data-meta-type": "ownership" }, content.length ? content : phrase ? [vue.h("span", { "data-meta-item": "true" }, phrase)] : [
1446
1497
  vue.h("span", { "data-meta-title": "true" }, firstText(props.title, props.label, props.heading, props.name) ?? "Ownership"),
1447
1498
  ...terms.map(([term, value]) => vue.h("span", { key: term, "data-meta-item": "true" }, [vue.h("strong", `${term}:`), ` ${value}`]))
1448
1499
  ]);
@@ -2168,6 +2219,63 @@ var Tabs = vue.defineComponent({
2168
2219
  ]);
2169
2220
  }
2170
2221
  });
2222
+ var SegmentedControl = vue.defineComponent({
2223
+ name: "OodsSegmentedControl",
2224
+ props: {
2225
+ id: String,
2226
+ label: String,
2227
+ modelValue: String,
2228
+ value: String,
2229
+ defaultValue: { type: String, default: "" },
2230
+ name: String,
2231
+ size: { type: String, default: "md" },
2232
+ disabled: Boolean,
2233
+ options: { type: Array, default: () => [] }
2234
+ },
2235
+ emits: {
2236
+ "update:modelValue": (_value) => true,
2237
+ change: (_value) => true
2238
+ },
2239
+ setup(props, { emit, slots }) {
2240
+ const generatedId = vue.useId();
2241
+ const internalValue = vue.ref(props.defaultValue);
2242
+ const currentValue = vue.computed(() => props.modelValue ?? props.value ?? internalValue.value);
2243
+ const select = (event) => {
2244
+ const next = event.target.value;
2245
+ if (props.modelValue === void 0 && props.value === void 0) internalValue.value = next;
2246
+ emit("update:modelValue", next);
2247
+ emit("change", next);
2248
+ };
2249
+ return () => {
2250
+ const id = props.id || `oods-segmentedcontrol-${generatedId}`;
2251
+ const label = slots.label?.() ?? props.label;
2252
+ return vue.h("div", {
2253
+ class: "oods-field oods-segmented-control",
2254
+ "data-oods-component": "SegmentedControl",
2255
+ "data-size": props.size
2256
+ }, [
2257
+ vue.h("span", { id: `${id}-label`, class: "oods-field-label" }, [label]),
2258
+ vue.h("div", {
2259
+ id,
2260
+ role: "radiogroup",
2261
+ "aria-labelledby": `${id}-label`,
2262
+ class: "oods-segmented-control__track"
2263
+ }, props.options.map((option) => vue.h("label", { key: option.value, class: "oods-segmented-control__option" }, [
2264
+ vue.h("input", {
2265
+ type: "radio",
2266
+ class: "oods-segmented-control__input",
2267
+ name: props.name || id,
2268
+ value: option.value,
2269
+ checked: option.value === currentValue.value,
2270
+ disabled: props.disabled || option.disabled,
2271
+ onChange: select
2272
+ }),
2273
+ vue.h("span", { class: "oods-segmented-control__label" }, option.label)
2274
+ ])))
2275
+ ]);
2276
+ };
2277
+ }
2278
+ });
2171
2279
  function isRecord2(value) {
2172
2280
  return typeof value === "object" && value !== null && !Array.isArray(value);
2173
2281
  }
@@ -2985,7 +3093,8 @@ var array = Array;
2985
3093
  function eventRecipe(id, kind, title) {
2986
3094
  return vue.defineComponent({ name: id, props: { id: String, title: { type: String, default: title }, archivedAt: String, restoredAt: String, archivedBy: String, reason: String, timestamp: String, code: String, history: array, status: String, showActor: { type: Boolean, default: true }, showReason: { type: Boolean, default: true } }, setup: (props) => () => {
2987
3095
  const rows = componentContracts.traitEventRows(kind, props);
2988
- return vue.h("article", { id: props.id, class: "oods-trait-recipe", "data-oods-component": id, "aria-label": props.title }, [vue.h("h2", props.title), rows.length ? vue.h("ol", rows.map((row, index) => vue.h("li", { key: index }, [vue.h("strong", row.title), vue.h("p", row.at ? vue.h("time", { datetime: row.at }, row.time) : row.time), row.actor && vue.h("p", `Actor: ${row.actor}`), row.reason && vue.h("p", `Reason: ${row.reason}`), row.code && vue.h("p", `Code: ${row.code}`)]))) : vue.h("p", "No events recorded.")]);
3096
+ if (!rows.length) return null;
3097
+ return vue.h("article", { id: props.id, class: "oods-trait-recipe", "data-oods-component": id, "aria-label": props.title }, [vue.h("h2", props.title), vue.h("ol", rows.map((row, index) => vue.h("li", { key: index }, [vue.h("strong", row.title), vue.h("p", row.at ? vue.h("time", { datetime: row.at }, row.time) : row.time), row.actor && vue.h("p", `Actor: ${row.actor}`), row.reason && vue.h("p", `Reason: ${row.reason}`), row.code && vue.h("p", `Code: ${row.code}`)])))]);
2989
3098
  } });
2990
3099
  }
2991
3100
  var ArchiveEvent = eventRecipe("ArchiveEvent", "archive", "Archive events");
@@ -3086,6 +3195,211 @@ var VizLinePreview = preview("VizLinePreview", "line");
3086
3195
  var VizMarkPreview = preview("VizMarkPreview", "bar");
3087
3196
  var VizPointPreview = preview("VizPointPreview", "scatter");
3088
3197
  var VizScatterPreview = preview("VizScatterPreview", "scatter");
3198
+ var Combobox = vue.defineComponent({
3199
+ name: "OodsCombobox",
3200
+ props: {
3201
+ id: String,
3202
+ label: String,
3203
+ options: { type: Array, default: () => [] },
3204
+ modelValue: String,
3205
+ value: String,
3206
+ defaultValue: { type: String, default: "" },
3207
+ placeholder: String,
3208
+ name: String,
3209
+ required: Boolean,
3210
+ disabled: Boolean,
3211
+ help: String,
3212
+ validation: Object,
3213
+ /** The control height, as Button, Input and Select: xs 24, sm 28, md 32 (default) or lg 40. */
3214
+ size: { type: String, default: "md" }
3215
+ },
3216
+ emits: {
3217
+ "update:modelValue": (_value) => true,
3218
+ change: (_value) => true
3219
+ },
3220
+ setup(props, { emit, slots }) {
3221
+ const generatedId = vue.useId();
3222
+ const controlId = vue.computed(() => props.id || `oods-combobox-${generatedId}`);
3223
+ const internalValue = vue.ref(props.defaultValue);
3224
+ const query = vue.ref(null);
3225
+ const open = vue.ref(false);
3226
+ const active = vue.ref(-1);
3227
+ const root = vue.ref(null);
3228
+ const listbox = vue.ref(null);
3229
+ const chosenValue = vue.computed(() => props.modelValue ?? props.value ?? internalValue.value);
3230
+ const chosen = vue.computed(() => props.options.find((option) => option.value === chosenValue.value));
3231
+ const text = vue.computed(() => query.value ?? chosen.value?.label ?? "");
3232
+ const matches = vue.computed(() => {
3233
+ const needle = (query.value ?? "").trim().toLowerCase();
3234
+ return props.options.map((option) => needle === "" || option.label.toLowerCase().includes(needle));
3235
+ });
3236
+ const reachable = vue.computed(() => props.options.flatMap((option, index) => matches.value[index] && !option.disabled ? [index] : []));
3237
+ const optionId = (index) => `${controlId.value}-option-${index}`;
3238
+ const close = () => {
3239
+ open.value = false;
3240
+ active.value = -1;
3241
+ };
3242
+ const commit = (next) => {
3243
+ if (props.modelValue === void 0 && props.value === void 0) internalValue.value = next;
3244
+ emit("update:modelValue", next);
3245
+ emit("change", next);
3246
+ };
3247
+ const pick = (index) => {
3248
+ const option = props.options[index];
3249
+ if (!option || option.disabled) return;
3250
+ query.value = null;
3251
+ close();
3252
+ if (option.value !== chosenValue.value) commit(option.value);
3253
+ };
3254
+ const outside = (event) => {
3255
+ if (!root.value?.contains(event.target)) close();
3256
+ };
3257
+ vue.watch(open, (isOpen) => {
3258
+ if (isOpen) document.addEventListener("pointerdown", outside);
3259
+ else document.removeEventListener("pointerdown", outside);
3260
+ });
3261
+ vue.onBeforeUnmount(() => {
3262
+ if (typeof document !== "undefined") document.removeEventListener("pointerdown", outside);
3263
+ });
3264
+ vue.watch([open, active], async () => {
3265
+ if (!open.value || active.value < 0) return;
3266
+ await vue.nextTick();
3267
+ const element = listbox.value?.children[active.value];
3268
+ element?.scrollIntoView?.({ block: "nearest" });
3269
+ });
3270
+ const keydown = (event) => {
3271
+ if (event.defaultPrevented || props.disabled || event.isComposing) return;
3272
+ const order = reachable.value;
3273
+ const first = order[0] ?? -1;
3274
+ const last = order[order.length - 1] ?? -1;
3275
+ const at = order.indexOf(active.value);
3276
+ switch (event.key) {
3277
+ case "ArrowDown":
3278
+ event.preventDefault();
3279
+ active.value = !open.value || at === -1 ? first : order[(at + 1) % order.length];
3280
+ open.value = true;
3281
+ return;
3282
+ case "ArrowUp":
3283
+ event.preventDefault();
3284
+ active.value = !open.value || at <= 0 ? last : order[at - 1];
3285
+ open.value = true;
3286
+ return;
3287
+ case "Home":
3288
+ case "End":
3289
+ if (!open.value) return;
3290
+ event.preventDefault();
3291
+ active.value = event.key === "Home" ? first : last;
3292
+ return;
3293
+ case "Enter":
3294
+ if (!open.value) return;
3295
+ event.preventDefault();
3296
+ if (active.value >= 0) pick(active.value);
3297
+ return;
3298
+ case "Escape":
3299
+ if (open.value) {
3300
+ event.preventDefault();
3301
+ close();
3302
+ return;
3303
+ }
3304
+ if (text.value === "" && chosenValue.value === "") return;
3305
+ event.preventDefault();
3306
+ query.value = null;
3307
+ if (chosenValue.value !== "") commit("");
3308
+ return;
3309
+ case "Tab":
3310
+ if (open.value) close();
3311
+ return;
3312
+ }
3313
+ };
3314
+ return () => {
3315
+ const id = controlId.value;
3316
+ const label = slots.label?.() ?? props.label;
3317
+ const help = slots.help?.() ?? props.help;
3318
+ const validation = slots.validation?.() ?? props.validation?.message;
3319
+ const tone = props.validation ? props.validation.state === "error" ? "critical" : props.validation.state : void 0;
3320
+ const describedBy = [help ? `${id}-help` : void 0, validation ? `${id}-validation` : void 0].filter(Boolean).join(" ") || void 0;
3321
+ const noMatches = open.value && !matches.value.some(Boolean);
3322
+ return vue.h("div", {
3323
+ ref: root,
3324
+ class: "oods-field oods-combobox",
3325
+ ...tone ? { style: { "--cmp-input-message-border": `var(--sys-status-${tone}-border)`, "--cmp-input-message-text": `var(--sys-status-${tone}-text)` } } : {},
3326
+ "data-oods-component": "Combobox",
3327
+ "data-size": props.size,
3328
+ "data-validation-state": props.validation?.state
3329
+ }, [
3330
+ vue.h("label", { id: `${id}-label`, class: "oods-field-label", for: id }, [
3331
+ label,
3332
+ props.required ? vue.h("span", { class: "oods-field-required", "aria-hidden": "true" }, "*") : null
3333
+ ]),
3334
+ vue.h("div", { class: "oods-combobox__control" }, [
3335
+ vue.h("input", {
3336
+ id,
3337
+ type: "text",
3338
+ role: "combobox",
3339
+ class: "oods-field-control oods-combobox__input",
3340
+ value: text.value,
3341
+ placeholder: props.placeholder,
3342
+ autocomplete: "off",
3343
+ "aria-autocomplete": "list",
3344
+ "aria-expanded": open.value ? "true" : "false",
3345
+ "aria-controls": `${id}-listbox`,
3346
+ "aria-activedescendant": open.value && active.value >= 0 ? optionId(active.value) : void 0,
3347
+ "aria-describedby": describedBy,
3348
+ "aria-invalid": props.validation?.state === "error" ? "true" : void 0,
3349
+ required: props.required,
3350
+ disabled: props.disabled,
3351
+ onInput: (event) => {
3352
+ query.value = event.target.value;
3353
+ open.value = true;
3354
+ active.value = -1;
3355
+ },
3356
+ onKeydown: keydown,
3357
+ onClick: () => {
3358
+ if (!props.disabled) open.value = true;
3359
+ },
3360
+ onBlur: () => {
3361
+ query.value = null;
3362
+ close();
3363
+ }
3364
+ }),
3365
+ vue.h("span", { class: "oods-combobox__chevron", "aria-hidden": "true" }, [statusIcon("chevron-down")]),
3366
+ vue.h("div", {
3367
+ class: "oods-combobox__popup",
3368
+ hidden: !open.value,
3369
+ onMousedown: (event) => event.preventDefault()
3370
+ }, [
3371
+ vue.h(
3372
+ "ul",
3373
+ { ref: listbox, id: `${id}-listbox`, class: "oods-combobox__listbox", role: "listbox", "aria-labelledby": `${id}-label` },
3374
+ props.options.map((option, index) => vue.h("li", {
3375
+ key: option.value,
3376
+ id: optionId(index),
3377
+ class: "oods-combobox__option",
3378
+ role: "option",
3379
+ "aria-selected": option.value === chosenValue.value ? "true" : "false",
3380
+ "aria-disabled": option.disabled ? "true" : void 0,
3381
+ "data-value": option.value,
3382
+ "data-active": index === active.value ? "true" : void 0,
3383
+ hidden: !matches.value[index],
3384
+ onClick: () => pick(index),
3385
+ onPointermove: () => {
3386
+ if (!option.disabled && index !== active.value) active.value = index;
3387
+ }
3388
+ }, [
3389
+ vue.h("span", { class: "oods-combobox__option-label" }, option.label),
3390
+ vue.h("span", { class: "oods-combobox__check", "aria-hidden": "true" }, [statusIcon("check")])
3391
+ ]))
3392
+ ),
3393
+ vue.h("p", { class: "oods-combobox__empty", role: "status" }, noMatches ? "No matches" : "")
3394
+ ])
3395
+ ]),
3396
+ props.name ? vue.h("input", { type: "hidden", name: props.name, value: chosenValue.value }) : null,
3397
+ help ? vue.h("p", { id: `${id}-help`, class: "oods-field-help" }, help) : null,
3398
+ validation ? vue.h("p", { id: `${id}-validation`, class: "oods-field-error", role: props.validation?.state === "error" ? "alert" : void 0 }, validation) : null
3399
+ ]);
3400
+ };
3401
+ }
3402
+ });
3089
3403
 
3090
3404
  exports.AddressCollectionPanel = AddressCollectionPanel;
3091
3405
  exports.AddressEditor = AddressEditor;
@@ -3118,6 +3432,7 @@ exports.ClassificationPanel = ClassificationPanel;
3118
3432
  exports.ColorStatePicker = ColorStatePicker;
3119
3433
  exports.ColorSwatch = ColorSwatch;
3120
3434
  exports.ColorizedBadge = ColorizedBadge;
3435
+ exports.Combobox = Combobox;
3121
3436
  exports.CommunicationDetailPanel = CommunicationDetailPanel;
3122
3437
  exports.CycleProgressCard = CycleProgressCard;
3123
3438
  exports.DatePicker = DatePicker;
@@ -3153,6 +3468,7 @@ exports.RelativeTimestamp = RelativeTimestamp;
3153
3468
  exports.RoleAssignmentForm = RoleAssignmentForm;
3154
3469
  exports.RoleBadgeList = RoleBadgeList;
3155
3470
  exports.SearchInput = SearchInput;
3471
+ exports.SegmentedControl = SegmentedControl;
3156
3472
  exports.Select = Select;
3157
3473
  exports.SortIndicator = SortIndicator;
3158
3474
  exports.Stack = Stack;