@atomic-ui/ui-vue 0.3.0 → 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.
package/README.md CHANGED
@@ -1,15 +1,15 @@
1
1
  # @atomic-ui/ui-vue
2
2
 
3
- Vue components for every `@atomic-ui/ui` custom element. Arrays and objects are bound as DOM properties, props and events are typed, and every component and tag is in Vue's `GlobalComponents`.
3
+ Vue components for every `@atomic-ui/ui` custom element, and for every `@atomic-ui/strata` block in its `strata` entry. Arrays and objects are bound as DOM properties, props and events are typed, and every component and tag is in Vue's `GlobalComponents`.
4
4
 
5
5
  ```sh
6
6
  pnpm add @atomic-ui/ui @atomic-ui/ui-vue
7
7
  ```
8
8
 
9
- Tell Vue's compiler that tags starting with `impkt-` are custom elements, in `vite.config.ts`:
9
+ Tell Vue's compiler that tags starting with `impakt-` are custom elements, in `vite.config.ts`:
10
10
 
11
11
  ```ts
12
- vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.startsWith('impkt-') } } });
12
+ vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.startsWith('impakt-') } } });
13
13
  ```
14
14
 
15
15
  Then import the components where they are used:
@@ -17,28 +17,49 @@ Then import the components where they are used:
17
17
  ```vue
18
18
  <script setup lang="ts">
19
19
  import { ref } from 'vue';
20
- import { ImpktTable, ImpktPagination, ImpktTextInput } from '@atomic-ui/ui-vue';
20
+ import { ImpaktTable, ImpaktPagination, ImpaktTextInput } from '@atomic-ui/ui-vue';
21
21
 
22
22
  const page = ref(1);
23
23
  </script>
24
24
 
25
25
  <template>
26
- <ImpktTextInput label="Search cases" type="search" @change="(e) => (query = e.detail.value)" />
27
- <ImpktTable caption="Open cases" :columns="columns" :rows="rows" stack selectable @sort="(e) => sortBy(e.detail)" />
28
- <ImpktPagination :page="page" :pages="9" @page="(e) => (page = e.detail.page)" />
26
+ <ImpaktTextInput label="Search cases" type="search" @change="(e) => (query = e.detail.value)" />
27
+ <ImpaktTable caption="Open cases" :columns="columns" :rows="rows" stack selectable @sort="(e) => sortBy(e.detail)" />
28
+ <ImpaktPagination :page="page" :pages="9" @page="(e) => (page = e.detail.page)" />
29
29
  </template>
30
30
  ```
31
31
 
32
- Or register them all once with `app.use(AtomicUI)`, and write `<ImpktTable>` anywhere.
32
+ Or register them all once with `app.use(AtomicUI)`, and write `<ImpaktTable>` anywhere.
33
33
 
34
34
  Importing this package defines the elements, so nothing else needs importing first.
35
35
 
36
+ ## The Strata blocks
37
+
38
+ The blocks Strata builds sites from are in `@atomic-ui/strata`, and their components are in this package's `strata` entry. An app that uses them installs that package too:
39
+
40
+ ```sh
41
+ pnpm add @atomic-ui/ui @atomic-ui/strata @atomic-ui/ui-vue
42
+ ```
43
+
44
+ ```vue
45
+ <script setup lang="ts">
46
+ import { ImpaktHero, ImpaktCardGrid } from '@atomic-ui/ui-vue/strata';
47
+ </script>
48
+
49
+ <template>
50
+ <ImpaktHero heading="Homes made for the way you live" />
51
+ <ImpaktCardGrid :items="developments" columns="three" />
52
+ </template>
53
+ ```
54
+
55
+ `app.use(AtomicUIStrata)` registers every block, and every block and its tag is in `GlobalComponents`. They are generated from `@atomic-ui/strata`'s manifest by the same script and named the same way. The main entry and `AtomicUI` hold the product components only, so an app that uses no blocks never loads them. `@atomic-ui/strata` is an optional peer dependency.
56
+
36
57
  ## Names
37
58
 
38
- Each component is named after the element's class, so `impkt-table` is `ImpktTable`. Each `impkt-` event is an emit without the prefix: `impkt-change` is `@change`, `impkt-sort` is `@sort` and `impkt-close` is `@close`, and the handler receives the event with its typed `detail`.
59
+ Each component is named after the element's class, so `impakt-table` is `ImpaktTable`. Each `impakt-` event is an emit without the prefix: `impakt-change` is `@change`, `impakt-sort` is `@sort` and `impakt-close` is `@close`, and the handler receives the event with its typed `detail`.
39
60
 
40
61
  The components are generated from the component manifest when the package builds, by `scripts/generate.mjs`, so they always match the elements. The components 0.2.0 had keep their names, property bindings and emits.
41
62
 
42
63
  ## Writing the tags
43
64
 
44
- A template can also write the tags, such as `<impkt-table :columns="columns" @impkt-sort="sortBy">`. They are typed through `GlobalComponents` as well. Bind arrays and objects with `:` as usual; Vue sets them as properties on a custom element.
65
+ A template can also write the tags, such as `<impakt-table :columns="columns" @impakt-sort="sortBy">`. They are typed through `GlobalComponents` as well. Bind arrays and objects with `:` as usual; Vue sets them as properties on a custom element.
@@ -0,0 +1,27 @@
1
+ // packages/ui-vue/src/wrap.ts
2
+ import { defineComponent, h } from "vue";
3
+ function wrap(tag, domProps = [], events = {}) {
4
+ return defineComponent({
5
+ name: tag.replace(/(^|-)(\w)/g, (_, __, c) => c.toUpperCase()),
6
+ inheritAttrs: false,
7
+ slots: Object,
8
+ setup(_, { attrs, slots, emit }) {
9
+ return () => {
10
+ const bound = {};
11
+ for (const [key, value] of Object.entries(attrs)) {
12
+ bound[domProps.includes(key) ? `.${key}` : key] = value;
13
+ }
14
+ for (const [eventName, vueName] of Object.entries(events)) {
15
+ bound[`on${eventName.replace(/(^|-)(\w)/g, (_2, __, c) => c.toUpperCase())}`] = (e) => emit(vueName, e);
16
+ }
17
+ return h(tag, bound, slots.default?.());
18
+ };
19
+ },
20
+ emits: Object.values(events)
21
+ });
22
+ }
23
+
24
+ export {
25
+ wrap
26
+ };
27
+ //# sourceMappingURL=chunk-WM4MLN2U.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/wrap.ts"],"sourcesContent":["import { defineComponent, h, type DefineSetupFnComponent, type SlotsType, type VNode } from 'vue';\n\ntype Props = Record<string, unknown>;\n\n/** The emits of a wrapper, from its events: `{ change: CustomEvent<…> }` gives a typed `@change`. */\ntype EmitsOf<Events> = { [K in keyof Events]: (event: Events[K]) => true };\n\n/**\n * A Vue component around one element, typed: its props are the element's own\n * properties, and attributes by their HTML names, and its events are typed emits.\n */\nexport type ImpaktComponent<E, K extends keyof E, Attributes extends string, Events> = DefineSetupFnComponent<\n { [P in K]?: E[P] } & { [A in Attributes]?: string | number | boolean },\n EmitsOf<Events>,\n SlotsType<{ default?: () => VNode[] }>\n>;\n\n/**\n * Build a Vue component around one element.\n *\n * `domProps` names the props that must be bound as properties rather than\n * attributes — anything that is not a string, a number or a boolean. Everything\n * else goes through as an attribute, which is what a custom element expects and\n * what keeps the rendered markup readable.\n */\nexport function wrap(tag: string, domProps: string[] = [], events: Record<string, string> = {}) {\n return defineComponent({\n name: tag.replace(/(^|-)(\\w)/g, (_, __, c: string) => c.toUpperCase()),\n inheritAttrs: false,\n slots: Object as SlotsType<{ default?: () => VNode[] }>,\n setup(_, { attrs, slots, emit }) {\n return () => {\n const bound: Props = {};\n for (const [key, value] of Object.entries(attrs)) {\n bound[domProps.includes(key) ? `.${key}` : key] = value;\n }\n for (const [eventName, vueName] of Object.entries(events)) {\n bound[`on${eventName.replace(/(^|-)(\\w)/g, (_, __, c: string) => c.toUpperCase())}`] =\n (e: Event) => emit(vueName, e);\n }\n return h(tag, bound, slots.default?.());\n };\n },\n emits: Object.values(events),\n });\n}\n"],"mappings":";AAAA,SAAS,iBAAiB,SAAkE;AAyBrF,SAAS,KAAK,KAAa,WAAqB,CAAC,GAAG,SAAiC,CAAC,GAAG;AAC9F,SAAO,gBAAgB;AAAA,IACrB,MAAM,IAAI,QAAQ,cAAc,CAAC,GAAG,IAAI,MAAc,EAAE,YAAY,CAAC;AAAA,IACrE,cAAc;AAAA,IACd,OAAO;AAAA,IACP,MAAM,GAAG,EAAE,OAAO,OAAO,KAAK,GAAG;AAC/B,aAAO,MAAM;AACX,cAAM,QAAe,CAAC;AACtB,mBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,gBAAM,SAAS,SAAS,GAAG,IAAI,IAAI,GAAG,KAAK,GAAG,IAAI;AAAA,QACpD;AACA,mBAAW,CAAC,WAAW,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG;AACzD,gBAAM,KAAK,UAAU,QAAQ,cAAc,CAACA,IAAG,IAAI,MAAc,EAAE,YAAY,CAAC,CAAC,EAAE,IACjF,CAAC,MAAa,KAAK,SAAS,CAAC;AAAA,QACjC;AACA,eAAO,EAAE,KAAK,OAAO,MAAM,UAAU,CAAC;AAAA,MACxC;AAAA,IACF;AAAA,IACA,OAAO,OAAO,OAAO,MAAM;AAAA,EAC7B,CAAC;AACH;","names":["_"]}