@plexui/vue 0.16.0 → 0.18.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.
@@ -1,7 +1,8 @@
1
- import { maskitoDateOptionsGenerator, maskitoDateTimeOptionsGenerator, maskitoParseDate, maskitoParseDateTime, maskitoStringifyDate, maskitoStringifyDateTime, } from "@maskito/kit";
1
+ import { maskitoDateOptionsGenerator, maskitoDateTimeOptionsGenerator, } from "@maskito/kit";
2
2
  import { maskito as vMaskito } from "@maskito/vue";
3
3
  import { DateTime } from "luxon";
4
4
  import { computed, defineComponent, h, mergeProps, onBeforeUnmount, onMounted, ref, watch, withDirectives, } from "vue";
5
+ import { dateInputValueKey, dateInputZone, formatDateInput, keepTypedValue, maskDate, parseDateInput, } from "../../lib/dateInputText.js";
5
6
  import { Input } from "../Input/index.js";
6
7
  // Vue port of packages/ui/src/components/DateInput/DateInput.tsx: an Input
7
8
  // with a Maskito date (or date + time) mask, same options as React.
@@ -22,6 +23,9 @@ import { Input } from "../Input/index.js";
22
23
  // read the same way here, from the event bubbling through Input's container.
23
24
  // Input's `update:value` only keeps its controlled value in step, so Input
24
25
  // does not put the previous text back.
26
+ // - The text is made from the value's own fields in its own zone and read
27
+ // back into that zone (lib/dateInputText, shared with React), never through
28
+ // the browser's local Date.
25
29
  const DateInputComponent = defineComponent({
26
30
  name: "DateInput",
27
31
  inheritAttrs: false,
@@ -53,14 +57,24 @@ const DateInputComponent = defineComponent({
53
57
  },
54
58
  setup(props, { attrs, slots, emit, expose }) {
55
59
  const hasTime = computed(() => !!props.timeMode);
56
- // React memoizes on the dates' milliseconds, not on the DateTime objects
60
+ // React memoizes on the dates' milliseconds and the value's zone, not on the DateTime objects
61
+ const zone = computed(() => dateInputZone(props.value));
57
62
  const minMs = computed(() => props.min?.toMillis());
58
63
  const maxMs = computed(() => props.max?.toMillis());
64
+ const textFormat = computed(() => ({
65
+ mode: props.mode,
66
+ separator: props.separator,
67
+ timeMode: props.timeMode,
68
+ dateTimeSeparator: props.dateTimeSeparator,
69
+ min: minMs.value,
70
+ max: maxMs.value,
71
+ zone: zone.value,
72
+ }));
59
73
  const dateParams = computed(() => ({
60
74
  mode: props.mode,
61
75
  separator: props.separator,
62
- ...(minMs.value !== undefined ? { min: new Date(minMs.value) } : undefined),
63
- ...(maxMs.value !== undefined ? { max: new Date(maxMs.value) } : undefined),
76
+ ...(minMs.value !== undefined ? { min: maskDate(minMs.value, zone.value) } : undefined),
77
+ ...(maxMs.value !== undefined ? { max: maskDate(maxMs.value, zone.value) } : undefined),
64
78
  }));
65
79
  const dateTimeParams = computed(() => ({
66
80
  dateMode: props.mode,
@@ -68,32 +82,36 @@ const DateInputComponent = defineComponent({
68
82
  timeMode: props.timeMode ?? "HH:MM",
69
83
  dateTimeSeparator: props.dateTimeSeparator,
70
84
  ...(props.timeStep ? { timeStep: props.timeStep } : undefined),
71
- ...(minMs.value !== undefined ? { min: new Date(minMs.value) } : undefined),
72
- ...(maxMs.value !== undefined ? { max: new Date(maxMs.value) } : undefined),
85
+ ...(minMs.value !== undefined ? { min: maskDate(minMs.value, zone.value) } : undefined),
86
+ ...(maxMs.value !== undefined ? { max: maskDate(maxMs.value, zone.value) } : undefined),
73
87
  }));
74
- // Like React's memo, new options whenever either set of params changes
88
+ // Like React's memo, new options whenever either set of params changes. The mask shows a complete text as the
89
+ // value reads it (lib/dateInputText)
75
90
  const maskOptions = computed(() => {
76
91
  const date = dateParams.value;
77
92
  const dateTime = dateTimeParams.value;
78
- return hasTime.value ? maskitoDateTimeOptionsGenerator(dateTime) : maskitoDateOptionsGenerator(date);
93
+ const format = textFormat.value;
94
+ return keepTypedValue(hasTime.value ? maskitoDateTimeOptionsGenerator(dateTime) : maskitoDateOptionsGenerator(date), format);
79
95
  });
80
- const inputValue = ref("");
81
- const format = (date) => {
82
- if (!date)
83
- return "";
84
- return hasTime.value
85
- ? maskitoStringifyDateTime(date.toJSDate(), dateTimeParams.value)
86
- : maskitoStringifyDate(date.toJSDate(), dateParams.value);
87
- };
88
- const parse = (str) => hasTime.value ? maskitoParseDateTime(str, dateTimeParams.value) : maskitoParseDate(str, dateParams.value);
89
- // React formats the value in an effect: the first render (and the server
90
- // markup) has an empty field, without the clear button
91
- const syncInputValue = () => {
96
+ const format = (date) => formatDateInput(date, textFormat.value);
97
+ const parse = (str) => parseDateInput(str, textFormat.value);
98
+ // The first render, on the server too, already shows the value. A new
99
+ // value or format shows it again before the next render, as React does
100
+ // during its render
101
+ const inputValue = ref(format(props.value));
102
+ const syncKey = computed(() => [
103
+ dateInputValueKey(props.value),
104
+ props.mode,
105
+ props.separator,
106
+ props.timeMode,
107
+ props.dateTimeSeparator,
108
+ props.timeStep,
109
+ minMs.value,
110
+ maxMs.value,
111
+ ].join("|"));
112
+ watch(syncKey, () => {
92
113
  inputValue.value = format(props.value);
93
- };
94
- const valueMsKey = computed(() => props.value?.toMillis() ?? null);
95
- watch([valueMsKey, hasTime, dateParams, dateTimeParams], syncInputValue);
96
- onMounted(syncInputValue);
114
+ });
97
115
  const change = (value) => {
98
116
  emit("update:value", value);
99
117
  emit("change", value);
@@ -111,7 +129,7 @@ const DateInputComponent = defineComponent({
111
129
  }
112
130
  const parsed = parse(str);
113
131
  if (parsed) {
114
- change(DateTime.fromJSDate(parsed));
132
+ change(parsed);
115
133
  }
116
134
  };
117
135
  // Text that is not a complete date never reaches `change`, so leaving the
@@ -1 +1 @@
1
- {"version":3,"file":"DateInput.js","sourceRoot":"","sources":["../../../../src/components/DateInput/DateInput.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,GAKzB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EACL,QAAQ,EACR,eAA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AAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzE,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACpE,CACF,EACD,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAChC,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAQF,kEAAkE;AAClE,MAAM,CAAC,MAAM,SAAS,GAAG,kBAAwF,CAAA","sourcesContent":["import {\n maskitoDateOptionsGenerator,\n maskitoDateTimeOptionsGenerator,\n maskitoParseDate,\n maskitoParseDateTime,\n maskitoStringifyDate,\n maskitoStringifyDateTime,\n type MaskitoDateMode,\n type MaskitoDateParams,\n type MaskitoDateTimeParams,\n type MaskitoTimeMode,\n} from \"@maskito/kit\"\nimport { maskito as vMaskito } from \"@maskito/vue\"\nimport { DateTime } from \"luxon\"\nimport {\n computed,\n defineComponent,\n h,\n mergeProps,\n onBeforeUnmount,\n onMounted,\n ref,\n watch,\n withDirectives,\n type PropType,\n} from \"vue\"\nimport { Input, type InputProps } from \"../Input/index.js\"\n\n// Vue port of packages/ui/src/components/DateInput/DateInput.tsx: an Input\n// with a Maskito date (or date + time) mask, same options as React.\n//\n// - `value` + `update:value` (`v-model:value`) and `change` mirror React's\n// `value` + `onChange`: both fire with a Luxon DateTime once a complete\n// valid date is typed, and with `null` when the field is emptied or cleared.\n// What is typed in between stays in the field without an event until the\n// field loses focus, which shows the value again.\n// - Every other attribute, listener and the `startAdornment` /\n// `endAdornment` slots go to Input, like React's `...inputProps`. React\n// sets `onInput` and `onClear` itself, so `@input` and `@clear` given to\n// DateInput are dropped, as there.\n// - The mask is `@maskito/vue`'s directive on Input's container; its default\n// element predicate picks the <input> inside.\n// - React reads the typed text in a listener React delegates to the root, so\n// it runs after Maskito's own `input` listeners on the <input>. The text is\n// read the same way here, from the event bubbling through Input's container.\n// Input's `update:value` only keeps its controlled value in step, so Input\n// does not put the previous text back.\n\nconst DateInputComponent = defineComponent({\n name: \"DateInput\",\n inheritAttrs: false,\n props: {\n /** Selected date (Luxon DateTime). Bind `v-model:value`. */\n value: { type: [Object, null] as PropType<DateTime | null>, required: true as const },\n /** Date format: `dd/mm/yyyy`, `mm/dd/yyyy`, `yyyy/mm/dd`, ... @default \"dd/mm/yyyy\" */\n mode: { type: String as PropType<MaskitoDateMode>, default: \"dd/mm/yyyy\" },\n /** Character between date parts. @default \".\" */\n separator: { type: String, default: \".\" },\n /** Enables time input: `HH:MM`, `HH:MM:SS`, ... */\n timeMode: String as PropType<MaskitoTimeMode>,\n /** Separator between the date and time parts. @default \", \" */\n dateTimeSeparator: { type: String, default: \", \" },\n /** Arrow-key increment step for time segments. @default 0 */\n timeStep: { type: Number, default: 0 },\n /** Earliest allowed date */\n min: Object as PropType<DateTime>,\n /** Latest allowed date */\n max: Object as PropType<DateTime>,\n /** Shows the clear button while the input has a value. @default false */\n clearable: { type: Boolean, default: false },\n /** Generated from the format when not set */\n placeholder: String,\n },\n emits: {\n \"update:value\": (value: DateTime | null) => value === null || DateTime.isDateTime(value),\n \"change\": (value: DateTime | null) => value === null || DateTime.isDateTime(value),\n },\n setup(props, { attrs, slots, emit, expose }) {\n const hasTime = computed(() => !!props.timeMode)\n // React memoizes on the dates' milliseconds, not on the DateTime objects\n const minMs = computed(() => props.min?.toMillis())\n const maxMs = computed(() => props.max?.toMillis())\n\n const dateParams = computed<MaskitoDateParams>(() => ({\n mode: props.mode,\n separator: props.separator,\n ...(minMs.value !== undefined ? { min: new Date(minMs.value) } : undefined),\n ...(maxMs.value !== undefined ? { max: new Date(maxMs.value) } : undefined),\n }))\n\n const dateTimeParams = computed<MaskitoDateTimeParams>(() => ({\n dateMode: props.mode,\n dateSeparator: props.separator,\n timeMode: props.timeMode ?? \"HH:MM\",\n dateTimeSeparator: props.dateTimeSeparator,\n ...(props.timeStep ? { timeStep: props.timeStep } : undefined),\n ...(minMs.value !== undefined ? { min: new Date(minMs.value) } : undefined),\n ...(maxMs.value !== undefined ? { max: new Date(maxMs.value) } : undefined),\n }))\n\n // Like React's memo, new options whenever either set of params changes\n const maskOptions = computed(() => {\n const date = dateParams.value\n const dateTime = dateTimeParams.value\n return hasTime.value ? maskitoDateTimeOptionsGenerator(dateTime) : maskitoDateOptionsGenerator(date)\n })\n\n const inputValue = ref(\"\")\n\n const format = (date: DateTime | null) => {\n if (!date) return \"\"\n return hasTime.value\n ? maskitoStringifyDateTime(date.toJSDate(), dateTimeParams.value)\n : maskitoStringifyDate(date.toJSDate(), dateParams.value)\n }\n\n const parse = (str: string) =>\n hasTime.value ? maskitoParseDateTime(str, dateTimeParams.value) : maskitoParseDate(str, dateParams.value)\n\n // React formats the value in an effect: the first render (and the server\n // markup) has an empty field, without the clear button\n const syncInputValue = () => {\n inputValue.value = format(props.value)\n }\n const valueMsKey = computed(() => props.value?.toMillis() ?? null)\n watch([valueMsKey, hasTime, dateParams, dateTimeParams], syncInputValue)\n onMounted(syncInputValue)\n\n const change = (value: DateTime | null) => {\n emit(\"update:value\", value)\n emit(\"change\", value)\n }\n\n const inputComponent = ref<{ $el: HTMLElement; input: HTMLInputElement | null; focus: () => void } | null>(null)\n\n const handleInput = (evt: Event) => {\n const input = inputComponent.value?.input\n if (!input || evt.target !== input) return\n const str = input.value\n inputValue.value = str\n\n if (!str) {\n change(null)\n return\n }\n\n const parsed = parse(str)\n\n if (parsed) {\n change(DateTime.fromJSDate(parsed))\n }\n }\n\n // Text that is not a complete date never reaches `change`, so leaving the\n // field shows the value again instead of a date the value does not hold\n const handleBlur = () => {\n if (inputValue.value && !parse(inputValue.value)) {\n inputValue.value = format(props.value)\n }\n }\n\n const handleClear = () => {\n inputValue.value = \"\"\n change(null)\n }\n\n let container: HTMLElement | null = null\n onMounted(() => {\n container = inputComponent.value?.$el ?? null\n container?.addEventListener(\"input\", handleInput)\n })\n onBeforeUnmount(() => {\n container?.removeEventListener(\"input\", handleInput)\n container = null\n })\n\n const defaultPlaceholder = computed(() => {\n const datePart = props.mode.replace(/\\//g, props.separator).toUpperCase()\n if (!hasTime.value) return datePart\n return `${datePart}${props.dateTimeSeparator}${props.timeMode}`\n })\n\n expose({\n focus: () => inputComponent.value?.focus(),\n input: computed(() => inputComponent.value?.input ?? null),\n })\n\n return () => {\n const { inputMode, inputmode, ...inputProps } = attrs\n delete inputProps.onInput\n delete inputProps.onClear\n return withDirectives(\n h(\n Input,\n // mergeProps keeps the caller's `@blur` and runs it first, as React does\n mergeProps(inputProps, {\n // Accept both native and JSX spelling, without duplicate DOM attributes.\n \"inputmode\": inputMode ?? inputmode ?? (props.timeMode?.includes(\"AA\") ? \"text\" : \"numeric\"),\n \"ref\": inputComponent,\n \"value\": inputValue.value,\n \"onUpdate:value\": (str: string) => {\n inputValue.value = str\n },\n \"onBlur\": handleBlur,\n \"placeholder\": props.placeholder ?? defaultPlaceholder.value,\n \"onClear\": props.clearable ? handleClear : undefined,\n }),\n {\n ...(slots.startAdornment ? { startAdornment: slots.startAdornment } : {}),\n ...(slots.endAdornment ? { endAdornment: slots.endAdornment } : {}),\n },\n ),\n [[vMaskito, maskOptions.value]],\n )\n }\n },\n})\n\ntype DateInputOwnProps = InstanceType<typeof DateInputComponent>[\"$props\"]\n\n/** DateInput props plus the Input props and attributes that fall through to it. */\nexport type DateInputProps = DateInputOwnProps &\n Omit<InputProps, keyof DateInputOwnProps | \"defaultValue\" | \"onUpdate:value\" | \"onInput\" | \"onClear\" | \"type\">\n\n/** Masked text input for typing dates (Luxon DateTime values). */\nexport const DateInput = DateInputComponent as typeof DateInputComponent & { new (): { $props: DateInputProps } }\n"]}
1
+ {"version":3,"file":"DateInput.js","sourceRoot":"","sources":["../../../../src/components/DateInput/DateInput.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,GAKhC,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,OAAO,IAAI,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,yEAAyE;YACzE,UAAU,CAAC,UAAU,EAAE;gBACrB,yEAAyE;gBACzE,WAAW,EAAE,SAAS,IAAI,SAAS,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;gBAC5F,KAAK,EAAE,cAAc;gBACrB,OAAO,EAAE,UAAU,CAAC,KAAK;gBACzB,gBAAgB,EAAE,CAAC,GAAW,EAAE,EAAE;oBAChC,UAAU,CAAC,KAAK,GAAG,GAAG,CAAA;gBACxB,CAAC;gBACD,QAAQ,EAAE,UAAU;gBACpB,aAAa,EAAE,KAAK,CAAC,WAAW,IAAI,kBAAkB,CAAC,KAAK;gBAC5D,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;aACrD,CAAC,EACF;gBACE,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,KAAK,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzE,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACpE,CACF,EACD,CAAC,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAChC,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAQF,kEAAkE;AAClE,MAAM,CAAC,MAAM,SAAS,GAAG,kBAAwF,CAAA","sourcesContent":["import {\n maskitoDateOptionsGenerator,\n maskitoDateTimeOptionsGenerator,\n type MaskitoDateMode,\n type MaskitoDateParams,\n type MaskitoDateTimeParams,\n type MaskitoTimeMode,\n} from \"@maskito/kit\"\nimport { maskito as vMaskito } from \"@maskito/vue\"\nimport { DateTime } from \"luxon\"\nimport {\n computed,\n defineComponent,\n h,\n mergeProps,\n onBeforeUnmount,\n onMounted,\n ref,\n watch,\n withDirectives,\n type PropType,\n} from \"vue\"\nimport {\n dateInputValueKey,\n dateInputZone,\n formatDateInput,\n keepTypedValue,\n maskDate,\n parseDateInput,\n type DateInputFormat,\n} from \"../../lib/dateInputText.js\"\nimport { Input, type InputProps } from \"../Input/index.js\"\n\n// Vue port of packages/ui/src/components/DateInput/DateInput.tsx: an Input\n// with a Maskito date (or date + time) mask, same options as React.\n//\n// - `value` + `update:value` (`v-model:value`) and `change` mirror React's\n// `value` + `onChange`: both fire with a Luxon DateTime once a complete\n// valid date is typed, and with `null` when the field is emptied or cleared.\n// What is typed in between stays in the field without an event until the\n// field loses focus, which shows the value again.\n// - Every other attribute, listener and the `startAdornment` /\n// `endAdornment` slots go to Input, like React's `...inputProps`. React\n// sets `onInput` and `onClear` itself, so `@input` and `@clear` given to\n// DateInput are dropped, as there.\n// - The mask is `@maskito/vue`'s directive on Input's container; its default\n// element predicate picks the <input> inside.\n// - React reads the typed text in a listener React delegates to the root, so\n// it runs after Maskito's own `input` listeners on the <input>. The text is\n// read the same way here, from the event bubbling through Input's container.\n// Input's `update:value` only keeps its controlled value in step, so Input\n// does not put the previous text back.\n// - The text is made from the value's own fields in its own zone and read\n// back into that zone (lib/dateInputText, shared with React), never through\n// the browser's local Date.\n\nconst DateInputComponent = defineComponent({\n name: \"DateInput\",\n inheritAttrs: false,\n props: {\n /** Selected date (Luxon DateTime). Bind `v-model:value`. */\n value: { type: [Object, null] as PropType<DateTime | null>, required: true as const },\n /** Date format: `dd/mm/yyyy`, `mm/dd/yyyy`, `yyyy/mm/dd`, ... @default \"dd/mm/yyyy\" */\n mode: { type: String as PropType<MaskitoDateMode>, default: \"dd/mm/yyyy\" },\n /** Character between date parts. @default \".\" */\n separator: { type: String, default: \".\" },\n /** Enables time input: `HH:MM`, `HH:MM:SS`, ... */\n timeMode: String as PropType<MaskitoTimeMode>,\n /** Separator between the date and time parts. @default \", \" */\n dateTimeSeparator: { type: String, default: \", \" },\n /** Arrow-key increment step for time segments. @default 0 */\n timeStep: { type: Number, default: 0 },\n /** Earliest allowed date */\n min: Object as PropType<DateTime>,\n /** Latest allowed date */\n max: Object as PropType<DateTime>,\n /** Shows the clear button while the input has a value. @default false */\n clearable: { type: Boolean, default: false },\n /** Generated from the format when not set */\n placeholder: String,\n },\n emits: {\n \"update:value\": (value: DateTime | null) => value === null || DateTime.isDateTime(value),\n \"change\": (value: DateTime | null) => value === null || DateTime.isDateTime(value),\n },\n setup(props, { attrs, slots, emit, expose }) {\n const hasTime = computed(() => !!props.timeMode)\n // React memoizes on the dates' milliseconds and the value's zone, not on the DateTime objects\n const zone = computed(() => dateInputZone(props.value))\n const minMs = computed(() => props.min?.toMillis())\n const maxMs = computed(() => props.max?.toMillis())\n\n const textFormat = computed<DateInputFormat>(() => ({\n mode: props.mode,\n separator: props.separator,\n timeMode: props.timeMode,\n dateTimeSeparator: props.dateTimeSeparator,\n min: minMs.value,\n max: maxMs.value,\n zone: zone.value,\n }))\n\n const dateParams = computed<MaskitoDateParams>(() => ({\n mode: props.mode,\n separator: props.separator,\n ...(minMs.value !== undefined ? { min: maskDate(minMs.value, zone.value) } : undefined),\n ...(maxMs.value !== undefined ? { max: maskDate(maxMs.value, zone.value) } : undefined),\n }))\n\n const dateTimeParams = computed<MaskitoDateTimeParams>(() => ({\n dateMode: props.mode,\n dateSeparator: props.separator,\n timeMode: props.timeMode ?? \"HH:MM\",\n dateTimeSeparator: props.dateTimeSeparator,\n ...(props.timeStep ? { timeStep: props.timeStep } : undefined),\n ...(minMs.value !== undefined ? { min: maskDate(minMs.value, zone.value) } : undefined),\n ...(maxMs.value !== undefined ? { max: maskDate(maxMs.value, zone.value) } : undefined),\n }))\n\n // Like React's memo, new options whenever either set of params changes. The mask shows a complete text as the\n // value reads it (lib/dateInputText)\n const maskOptions = computed(() => {\n const date = dateParams.value\n const dateTime = dateTimeParams.value\n const format = textFormat.value\n return keepTypedValue(\n hasTime.value ? maskitoDateTimeOptionsGenerator(dateTime) : maskitoDateOptionsGenerator(date),\n format,\n )\n })\n\n const format = (date: DateTime | null) => formatDateInput(date, textFormat.value)\n const parse = (str: string) => parseDateInput(str, textFormat.value)\n\n // The first render, on the server too, already shows the value. A new\n // value or format shows it again before the next render, as React does\n // during its render\n const inputValue = ref(format(props.value))\n const syncKey = computed(() =>\n [\n dateInputValueKey(props.value),\n props.mode,\n props.separator,\n props.timeMode,\n props.dateTimeSeparator,\n props.timeStep,\n minMs.value,\n maxMs.value,\n ].join(\"|\"),\n )\n watch(syncKey, () => {\n inputValue.value = format(props.value)\n })\n\n const change = (value: DateTime | null) => {\n emit(\"update:value\", value)\n emit(\"change\", value)\n }\n\n const inputComponent = ref<{ $el: HTMLElement; input: HTMLInputElement | null; focus: () => void } | null>(null)\n\n const handleInput = (evt: Event) => {\n const input = inputComponent.value?.input\n if (!input || evt.target !== input) return\n const str = input.value\n inputValue.value = str\n\n if (!str) {\n change(null)\n return\n }\n\n const parsed = parse(str)\n\n if (parsed) {\n change(parsed)\n }\n }\n\n // Text that is not a complete date never reaches `change`, so leaving the\n // field shows the value again instead of a date the value does not hold\n const handleBlur = () => {\n if (inputValue.value && !parse(inputValue.value)) {\n inputValue.value = format(props.value)\n }\n }\n\n const handleClear = () => {\n inputValue.value = \"\"\n change(null)\n }\n\n let container: HTMLElement | null = null\n onMounted(() => {\n container = inputComponent.value?.$el ?? null\n container?.addEventListener(\"input\", handleInput)\n })\n onBeforeUnmount(() => {\n container?.removeEventListener(\"input\", handleInput)\n container = null\n })\n\n const defaultPlaceholder = computed(() => {\n const datePart = props.mode.replace(/\\//g, props.separator).toUpperCase()\n if (!hasTime.value) return datePart\n return `${datePart}${props.dateTimeSeparator}${props.timeMode}`\n })\n\n expose({\n focus: () => inputComponent.value?.focus(),\n input: computed(() => inputComponent.value?.input ?? null),\n })\n\n return () => {\n const { inputMode, inputmode, ...inputProps } = attrs\n delete inputProps.onInput\n delete inputProps.onClear\n return withDirectives(\n h(\n Input,\n // mergeProps keeps the caller's `@blur` and runs it first, as React does\n mergeProps(inputProps, {\n // Accept both native and JSX spelling, without duplicate DOM attributes.\n \"inputmode\": inputMode ?? inputmode ?? (props.timeMode?.includes(\"AA\") ? \"text\" : \"numeric\"),\n \"ref\": inputComponent,\n \"value\": inputValue.value,\n \"onUpdate:value\": (str: string) => {\n inputValue.value = str\n },\n \"onBlur\": handleBlur,\n \"placeholder\": props.placeholder ?? defaultPlaceholder.value,\n \"onClear\": props.clearable ? handleClear : undefined,\n }),\n {\n ...(slots.startAdornment ? { startAdornment: slots.startAdornment } : {}),\n ...(slots.endAdornment ? { endAdornment: slots.endAdornment } : {}),\n },\n ),\n [[vMaskito, maskOptions.value]],\n )\n }\n },\n})\n\ntype DateInputOwnProps = InstanceType<typeof DateInputComponent>[\"$props\"]\n\n/** DateInput props plus the Input props and attributes that fall through to it. */\nexport type DateInputProps = DateInputOwnProps &\n Omit<InputProps, keyof DateInputOwnProps | \"defaultValue\" | \"onUpdate:value\" | \"onInput\" | \"onClear\" | \"type\">\n\n/** Masked text input for typing dates (Luxon DateTime values). */\nexport const DateInput = DateInputComponent as typeof DateInputComponent & { new (): { $props: DateInputProps } }\n"]}
@@ -1,20 +1,8 @@
1
1
  import { defineComponent, h, reactive, ref, watch, } from "vue";
2
2
  import { EditorContent, useEditor } from "@tiptap/vue-3";
3
3
  import { getMarkRange } from "@tiptap/core";
4
- import Document from "@tiptap/extension-document";
5
- import Paragraph from "@tiptap/extension-paragraph";
6
- import Text from "@tiptap/extension-text";
7
- import BoldExtension from "@tiptap/extension-bold";
8
- import ItalicExtension from "@tiptap/extension-italic";
9
- import LinkExtension from "@tiptap/extension-link";
10
- import BulletList from "@tiptap/extension-bullet-list";
11
- import OrderedList from "@tiptap/extension-ordered-list";
12
- import ListItem from "@tiptap/extension-list-item";
13
- import History from "@tiptap/extension-history";
14
- import Placeholder from "@tiptap/extension-placeholder";
15
- import HardBreak from "@tiptap/extension-hard-break";
16
- import { Markdown as MarkdownExtension } from "tiptap-markdown";
17
4
  import { keepMovedFocus } from "../../lib/helpers.js";
5
+ import { markdownEditorExtensions, markdownEditorSchema, rehypeEditorSchema, remarkLineBreaks, remarkWithoutHtml, } from "../../lib/markdownEditorSchema.js";
18
6
  import { Bold as BoldIcon, Italic as ItalicIcon, Link as LinkIcon, List as ListIcon, ListNumbers as ListNumbersIcon, } from "../Icon/index.js";
19
7
  import { Tooltip } from "../Tooltip/index.js";
20
8
  import { Button } from "../Button/index.js";
@@ -142,6 +130,17 @@ const MarkdownEditorComponent = defineComponent({
142
130
  value: { type: String, default: undefined },
143
131
  /** Default value as a markdown string for uncontrolled mode */
144
132
  defaultValue: { type: String, default: undefined },
133
+ /**
134
+ * The formats the editor offers, read when the editor is created. A format left out has no toolbar button,
135
+ * shortcut or input rule; pasted and incoming content keeps its text without it, and the markdown does not write it.
136
+ * @default ["bold", "italic", "orderedList", "bulletList", "link"]
137
+ */
138
+ formats: { type: Array, default: undefined },
139
+ /**
140
+ * A single newline is a line break, read and written as one "\n", read when the editor is created. Without it a
141
+ * line break is written as a backslash and a newline, and a single newline joins the lines. @default false
142
+ */
143
+ breaks: { type: Boolean, default: false },
145
144
  /** Minimum visible rows. @default 1 */
146
145
  rows: { type: Number, default: 1 },
147
146
  /** `id` of the editable element */
@@ -162,6 +161,8 @@ const MarkdownEditorComponent = defineComponent({
162
161
  "change": (markdown) => typeof markdown === "string",
163
162
  },
164
163
  setup(props, { slots, attrs, emit }) {
164
+ // The schema is the editor's, made once with it, as the toolbar offers what the schema has
165
+ const schema = markdownEditorSchema(props.formats, props.breaks);
165
166
  const focused = ref(false);
166
167
  const linkDialogOpen = ref(false);
167
168
  const linkDialogInitial = ref({ url: "", title: "" });
@@ -198,28 +199,7 @@ const MarkdownEditorComponent = defineComponent({
198
199
  ...(props.ariaInvalid && { "aria-invalid": "true" }),
199
200
  });
200
201
  const editor = useEditor({
201
- extensions: [
202
- Document,
203
- Paragraph,
204
- Text,
205
- HardBreak,
206
- BoldExtension,
207
- ItalicExtension,
208
- LinkExtension.configure({
209
- openOnClick: false,
210
- HTMLAttributes: { rel: "noopener noreferrer nofollow" },
211
- }),
212
- BulletList,
213
- OrderedList,
214
- ListItem,
215
- History,
216
- MarkdownExtension.configure({
217
- html: false,
218
- transformPastedText: true,
219
- transformCopiedText: true,
220
- }),
221
- ...(props.placeholder ? [Placeholder.configure({ placeholder: props.placeholder })] : []),
222
- ],
202
+ extensions: markdownEditorExtensions(schema, props.placeholder),
223
203
  content: props.value ?? props.defaultValue ?? "",
224
204
  editable: !props.disabled,
225
205
  editorProps: {
@@ -368,6 +348,51 @@ const MarkdownEditorComponent = defineComponent({
368
348
  // React renders the slot only for a truthy `toolbarEnd`
369
349
  const toolbarEnd = slots.toolbarEnd?.();
370
350
  const hasToolbarEnd = flattenSlot(toolbarEnd).length > 0;
351
+ const offered = schema.formats;
352
+ // Groups of the offered formats, a separator between two of them
353
+ const groups = [
354
+ [
355
+ offered.has("bold") && h(ToolbarButton, {
356
+ tooltip: "Bold",
357
+ active: activeMarks.bold,
358
+ disabled,
359
+ icon: BoldIcon,
360
+ onClick: () => editor.value?.chain().focus().toggleBold().run(),
361
+ }),
362
+ offered.has("italic") && h(ToolbarButton, {
363
+ tooltip: "Italic",
364
+ active: activeMarks.italic,
365
+ disabled,
366
+ icon: ItalicIcon,
367
+ onClick: () => editor.value?.chain().focus().toggleItalic().run(),
368
+ }),
369
+ ],
370
+ [
371
+ offered.has("orderedList") && h(ToolbarButton, {
372
+ tooltip: "Numbered list",
373
+ active: activeMarks.orderedList,
374
+ disabled,
375
+ icon: ListNumbersIcon,
376
+ onClick: () => editor.value?.chain().focus().toggleOrderedList().run(),
377
+ }),
378
+ offered.has("bulletList") && h(ToolbarButton, {
379
+ tooltip: "Bullet list",
380
+ active: activeMarks.bulletList,
381
+ disabled,
382
+ icon: ListIcon,
383
+ onClick: () => editor.value?.chain().focus().toggleBulletList().run(),
384
+ }),
385
+ ],
386
+ [
387
+ offered.has("link") && h(ToolbarButton, {
388
+ tooltip: "Link",
389
+ active: activeMarks.link,
390
+ disabled: disabled || !linkCanEnable.value,
391
+ icon: LinkIcon,
392
+ onClick: openLinkDialog,
393
+ }),
394
+ ],
395
+ ].map((group) => group.filter((button) => button !== false)).filter((group) => group.length > 0);
371
396
  return h("div", {
372
397
  "class": [s.Container, attrs.class],
373
398
  "data-variant": variant,
@@ -376,57 +401,26 @@ const MarkdownEditorComponent = defineComponent({
376
401
  "data-invalid": isInvalid ? "" : undefined,
377
402
  "onMousedown": handleContainerMouseDown,
378
403
  }, [
379
- h("div", { class: s.Toolbar, onMousedown: (e) => e.preventDefault() }, [
380
- h("div", { class: s.ToolbarGroup }, [
381
- h(ToolbarButton, {
382
- tooltip: "Bold",
383
- active: activeMarks.bold,
384
- disabled,
385
- icon: BoldIcon,
386
- onClick: () => editor.value?.chain().focus().toggleBold().run(),
387
- }),
388
- h(ToolbarButton, {
389
- tooltip: "Italic",
390
- active: activeMarks.italic,
391
- disabled,
392
- icon: ItalicIcon,
393
- onClick: () => editor.value?.chain().focus().toggleItalic().run(),
394
- }),
395
- h("div", { "class": s.ToolbarSeparator, "aria-hidden": "true" }),
396
- h(ToolbarButton, {
397
- tooltip: "Numbered list",
398
- active: activeMarks.orderedList,
399
- disabled,
400
- icon: ListNumbersIcon,
401
- onClick: () => editor.value?.chain().focus().toggleOrderedList().run(),
402
- }),
403
- h(ToolbarButton, {
404
- tooltip: "Bullet list",
405
- active: activeMarks.bulletList,
406
- disabled,
407
- icon: ListIcon,
408
- onClick: () => editor.value?.chain().focus().toggleBulletList().run(),
409
- }),
410
- h("div", { "class": s.ToolbarSeparator, "aria-hidden": "true" }),
411
- h(ToolbarButton, {
412
- tooltip: "Link",
413
- active: activeMarks.link,
414
- disabled: disabled || !linkCanEnable.value,
415
- icon: LinkIcon,
416
- onClick: openLinkDialog,
417
- }),
418
- ...(hasToolbarEnd
419
- ? [
420
- h("div", { "class": s.ToolbarSeparator, "aria-hidden": "true" }),
421
- h("div", { class: s.ToolbarEnd }, toolbarEnd),
422
- ]
423
- : []),
424
- ]),
425
- ]),
404
+ groups.length || hasToolbarEnd
405
+ ? h("div", { class: s.Toolbar, onMousedown: (e) => e.preventDefault() }, [
406
+ h("div", { class: s.ToolbarGroup }, [
407
+ ...groups.flatMap((group, index) => [
408
+ ...(index ? [h("div", { "class": s.ToolbarSeparator, "aria-hidden": "true" })] : []),
409
+ ...group,
410
+ ]),
411
+ ...(hasToolbarEnd
412
+ ? [
413
+ ...(groups.length ? [h("div", { "class": s.ToolbarSeparator, "aria-hidden": "true" })] : []),
414
+ h("div", { class: s.ToolbarEnd }, toolbarEnd),
415
+ ]
416
+ : []),
417
+ ]),
418
+ ])
419
+ : null,
426
420
  h("div", { class: s.Editor, style: { minHeight: `${minHeight}px` } }, [
427
421
  editor.value
428
422
  ? h(EditorContent, { editor: editor.value })
429
- : editorFirstFrame(props.value ?? props.defaultValue ?? "", props.placeholder, props.disabled),
423
+ : editorFirstFrame(props.value ?? props.defaultValue ?? "", props.placeholder, props.disabled, schema),
430
424
  ]),
431
425
  h(LinkDialog, {
432
426
  open: linkDialogOpen.value,
@@ -443,147 +437,21 @@ const MarkdownEditorComponent = defineComponent({
443
437
  };
444
438
  },
445
439
  });
446
- // The editor reads markdown with `html: false` (markdown-it): HTML is not parsed, its characters are text, and the
447
- // markdown around and inside it still is
448
- function remarkWithoutHtml() {
449
- const data = this.data();
450
- (data.micromarkExtensions ??= []).push({ disable: { null: ["htmlFlow", "htmlText"] } });
451
- }
452
- // The editor's schema keeps paragraphs, lists, bold, italic, links and line breaks. ProseMirror parses anything else
453
- // into them: a heading is a paragraph of its text, a code block a paragraph of its lines, a quote its paragraphs,
454
- // inline code its text, an image or a rule nothing, and the text of a list item sits in a paragraph. Outside a code
455
- // block it collapses white space, as the page does; the editor's text keeps its spaces (white-space: break-spaces)
456
- const SCHEMA_AS_PARAGRAPH = new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
457
- const SCHEMA_BLOCKS = new Set(["p", "ul", "ol"]);
458
- const textOf = (node) => node.value ?? (node.children ?? []).map(textOf).join("");
459
- const isBlank = (node) => node.type === "text" && !node.value?.trim();
460
- const lineBreak = () => ({ type: "element", tagName: "br", properties: {}, children: [] });
461
- // White space of a paragraph's text as ProseMirror parses it: runs collapse to one space, none at the start of the
462
- // paragraph, after a line break or after another space, none at its end
463
- function collapseWhiteSpace(children) {
464
- let previous = null;
465
- let lineStart = true;
466
- const walk = (nodes) => {
467
- for (const node of nodes) {
468
- if (node.type === "text") {
469
- let value = (node.value ?? "").replace(/[ \t\r\n\f]+/g, " ");
470
- if (value.startsWith(" ") && (lineStart || previous?.value?.endsWith(" ")))
471
- value = value.slice(1);
472
- node.value = value;
473
- if (value) {
474
- previous = node;
475
- lineStart = false;
476
- }
477
- }
478
- else if (node.tagName === "br") {
479
- lineStart = true;
480
- }
481
- else {
482
- walk(node.children ?? []);
483
- }
484
- }
485
- };
486
- walk(children);
487
- if (previous)
488
- previous.value = previous.value.replace(/ $/, "");
489
- }
490
- const paragraph = (children, { preserveWhiteSpace = false } = {}) => {
491
- if (!preserveWhiteSpace)
492
- collapseWhiteSpace(children);
493
- return {
494
- type: "element",
495
- tagName: "p",
496
- properties: {},
497
- // An empty paragraph keeps its line, as ProseMirror's trailing break does
498
- children: children.every((child) => child.type === "text" && !child.value) ? [lineBreak()] : children,
499
- };
500
- };
501
- // tiptap-markdown drops the newline markdown-it writes after an element, outside a code block: a line that follows
502
- // bold, a link or code joins it without a space
503
- const dropNewlineAfterElements = (nodes) => nodes.map((node, index) => index && node.type === "text" && nodes[index - 1].type === "element" && node.value?.startsWith("\n")
504
- ? { ...node, value: node.value.slice(1) }
505
- : node);
506
- function toEditorSchema(nodes) {
507
- return dropNewlineAfterElements(nodes).flatMap((node) => {
508
- if (node.type !== "element")
509
- return [node];
510
- const children = node.children ?? [];
511
- switch (node.tagName) {
512
- case "img":
513
- case "hr":
514
- return [];
515
- case "code":
516
- return [{ type: "text", value: textOf(node) }];
517
- case "pre": {
518
- // ProseMirror keeps a code block's spaces and its newlines as line breaks, the last one followed by the
519
- // trailing break of a paragraph that ends in a break
520
- const lines = textOf(node).split("\n");
521
- if (lines.every((line) => !line))
522
- return [];
523
- const content = [];
524
- lines.forEach((line, index) => {
525
- if (index)
526
- content.push(lineBreak());
527
- if (line)
528
- content.push({ type: "text", value: line });
529
- });
530
- if (content[content.length - 1].tagName === "br")
531
- content.push(lineBreak());
532
- return [paragraph(content, { preserveWhiteSpace: true })];
533
- }
534
- case "blockquote":
535
- return toEditorSchema(children);
536
- case "p":
537
- return [paragraph(toEditorSchema(children))];
538
- case "li": {
539
- const content = [];
540
- let run = [];
541
- const flush = () => {
542
- if (!run.every(isBlank))
543
- content.push(paragraph(run));
544
- run = [];
545
- };
546
- for (const child of toEditorSchema(children)) {
547
- if (child.type === "element" && SCHEMA_BLOCKS.has(child.tagName)) {
548
- flush();
549
- content.push(child);
550
- }
551
- else {
552
- run.push(child);
553
- }
554
- }
555
- flush();
556
- // A list item starts with a paragraph, an empty one if it has no text (an empty item, an image)
557
- if (content[0]?.tagName !== "p")
558
- content.unshift(paragraph([]));
559
- return [{ ...node, children: content }];
560
- }
561
- case "ul":
562
- case "ol":
563
- return [{ ...node, children: toEditorSchema(children).filter((child) => !isBlank(child)) }];
564
- default:
565
- return SCHEMA_AS_PARAGRAPH.has(node.tagName)
566
- ? [paragraph(toEditorSchema(children))]
567
- : [{ ...node, children: toEditorSchema(children) }];
568
- }
569
- });
570
- }
571
- function rehypeEditorSchema() {
572
- return (tree) => {
573
- tree.children = toEditorSchema(tree.children ?? []).filter((child) => !isBlank(child));
574
- };
575
- }
576
440
  /**
577
441
  * The content before the editor exists, on the server and until it mounts: the markdown as the editor will show it,
578
442
  * in its schema and its own boxes (EditorContent's, then ProseMirror's), so the page does not move when ProseMirror
579
443
  * takes over, as in React. An empty editor shows its placeholder while it can be edited (`showOnlyWhenEditable`).
580
444
  */
581
- const editorFirstFrame = (markdown, placeholder, disabled) => {
582
- const hint = placeholder && !disabled;
445
+ const editorFirstFrame = (markdown, placeholder, disabled, schema) => {
446
+ const hint = placeholder && !disabled ? placeholder : undefined;
583
447
  return h("div", null, [
584
448
  h("div", { class: ["tiptap", s.EditorContent] }, [
585
449
  markdown.trim()
586
- ? renderMarkdown({ children: markdown, remarkPlugins: [remarkWithoutHtml], rehypePlugins: [rehypeEditorSchema] })
450
+ ? renderMarkdown({
451
+ children: markdown,
452
+ remarkPlugins: schema.breaks ? [remarkWithoutHtml, remarkLineBreaks] : [remarkWithoutHtml],
453
+ rehypePlugins: [rehypeEditorSchema(schema, hint)],
454
+ })
587
455
  : h("p", { class: hint ? "is-editor-empty" : undefined, "data-placeholder": hint ? placeholder : undefined }, [h("br")]),
588
456
  ]),
589
457
  ]);