diff --git a/packages/bbob-preset-react/src/index.ts b/packages/bbob-preset-react/src/index.ts index cb8a4dbc..6664b8d6 100644 --- a/packages/bbob-preset-react/src/index.ts +++ b/packages/bbob-preset-react/src/index.ts @@ -1,5 +1,5 @@ import presetHTML5 from '@bbob/preset-html5'; -import type { PresetTagsDefinition } from '@bbob/preset'; +import type { PresetTagsDefinition } from '@bbob/preset-html5'; const tagAttr = (style: Record) => ({ attrs: { @@ -7,7 +7,7 @@ const tagAttr = (style: Record) => ({ }, }); -export default presetHTML5.extend((tags: PresetTagsDefinition<'b' | 'i' | 'u' | 's'>) => ({ +const presetReact = presetHTML5.extend((tags: PresetTagsDefinition<'b' | 'i' | 'u' | 's'>) => ({ ...tags, b: (...args) => ({ @@ -30,3 +30,5 @@ export default presetHTML5.extend((tags: PresetTagsDefinition<'b' | 'i' | 'u' | ...tagAttr({ textDecoration: 'line-through' }), }), })); + +export default presetReact; diff --git a/packages/bbob-preset-vue/package.json b/packages/bbob-preset-vue/package.json index df5b8ec4..3eee6ec1 100644 --- a/packages/bbob-preset-vue/package.json +++ b/packages/bbob-preset-vue/package.json @@ -8,8 +8,7 @@ "vue" ], "dependencies": { - "@bbob/preset-html5": "*", - "@bbob/preset": "*" + "@bbob/preset-html5": "*" }, "devDependencies": { "@bbob/core": "*" diff --git a/packages/bbob-preset-vue/src/index.ts b/packages/bbob-preset-vue/src/index.ts index 9b10f539..2bde6da7 100644 --- a/packages/bbob-preset-vue/src/index.ts +++ b/packages/bbob-preset-vue/src/index.ts @@ -1,5 +1,5 @@ import presetHTML5 from '@bbob/preset-html5'; -import type { PresetTagsDefinition } from '@bbob/preset'; +import type { PresetTagsDefinition } from '@bbob/preset-html5'; export const tagAttr = (style: Record) => ({ attrs: { @@ -7,29 +7,39 @@ export const tagAttr = (style: Record) => ({ }, }); -export const createTags = (tags: Tags) => ({ - b: (...args) => ({ - ...tags.b?.(...args), - ...tagAttr({ fontWeight: 'bold' }), - }), - - i: (...args) => ({ - ...tags.i?.(...args), - ...tagAttr({ fontStyle: 'italic' }), - }), - - u: (...args) => ({ - ...tags.u?.(...args), - ...tagAttr({ textDecoration: 'underline' }), - }), - - s: (...args) => ({ - ...tags.s?.(...args), - ...tagAttr({ textDecoration: 'line-through' }), - }), -}); +export const createTags = (tags: PresetTagsDefinition) => { + const newTags: PresetTagsDefinition = { + b: (...args) => ({ + ...tags.b?.(...args), + ...tagAttr({ fontWeight: 'bold' }), + tag: 'b', + }), + + i: (...args) => ({ + ...tags.i?.(...args), + ...tagAttr({ fontStyle: 'italic' }), + tag: 'i', + }), + + u: (...args) => ({ + ...tags.u?.(...args), + ...tagAttr({ textDecoration: 'underline' }), + tag: 'u', + }), -export default presetHTML5.extend((tags) => ({ + s: (...args) => ({ + ...tags.s?.(...args), + ...tagAttr({ textDecoration: 'line-through' }), + tag: 's', + }), + } + + return newTags +}; + +const presetVue = presetHTML5.extend((tags: PresetTagsDefinition) => ({ ...tags, ...createTags(tags), })); + +export default presetVue; diff --git a/packages/bbob-preset-vue/test/index.test.ts b/packages/bbob-preset-vue/test/index.test.ts index 9c57a3a9..7f4c9942 100644 --- a/packages/bbob-preset-vue/test/index.test.ts +++ b/packages/bbob-preset-vue/test/index.test.ts @@ -14,10 +14,11 @@ describe('@bbob/preset-vue', () => { s: defFn, } const tags = createTags(defTags) + const args = [{tag: 'test'}] - expect(tags.b()).toEqual(tagAttr({ fontWeight: 'bold' })) - expect(tags.i()).toEqual(tagAttr({ fontStyle: 'italic' })) - expect(tags.u()).toEqual(tagAttr({ textDecoration: 'underline' })) - expect(tags.s()).toEqual(tagAttr({ textDecoration: 'line-through' })) + expect(tags.b?.({tag: 'b'}, ...args)).toEqual(tagAttr({ fontWeight: 'bold' })) + expect(tags.i?.({tag: 'i'}, ...args)).toEqual(tagAttr({ fontStyle: 'italic' })) + expect(tags.u?.({tag: 'u'}, ...args)).toEqual(tagAttr({ textDecoration: 'underline' })) + expect(tags.s?.({tag: 's'}, ...args)).toEqual(tagAttr({ textDecoration: 'line-through' })) }) }); diff --git a/packages/bbob-preset/src/types.ts b/packages/bbob-preset/src/types.ts index b29e04fe..bae969b9 100644 --- a/packages/bbob-preset/src/types.ts +++ b/packages/bbob-preset/src/types.ts @@ -4,6 +4,9 @@ import type { process } from "./preset"; type PartialRecord = Partial> +export type { TagNodeObject } from "@bbob/plugin-helper"; +export type { BBobCoreTagNodeTree, BBobPluginFunction, BBobPluginOptions } from "@bbob/core"; + export type PresetTagsDefinition = PartialRecord export type PresetOptions = Record diff --git a/packages/bbob-preset/test/index.test.ts b/packages/bbob-preset/test/index.test.ts index da00718e..8db1f5a8 100644 --- a/packages/bbob-preset/test/index.test.ts +++ b/packages/bbob-preset/test/index.test.ts @@ -29,8 +29,8 @@ describe('@bbob/preset', () => { expect(processor.mock.calls.length).toBe(1); }); test('extend', () => { - const defTags = { foo: () => 'foo' } - const extendedTags = { bar: () => 'bar' } + const defTags = { foo: () => ({ tag: 'foo'}) } + const extendedTags = { bar: () =>({tag: 'bar'}) } const options = { foo: 'bar' } const tree = createTree([], {}) const { preset, processor, core } = presetFactory(defTags); @@ -48,8 +48,8 @@ describe('@bbob/preset', () => { expect(processor.mock.calls.length).toBe(1); }); test('pass options', () => { - const { preset, processor } = presetFactory({ test: () => 'test' }); - const newPreset = preset.extend((tags, options) => ({ bar: () => 'bar' })); + const { preset } = presetFactory({ test: () => ({tag: 'test'}) }); + const newPreset = preset.extend((tags, options) => ({ bar: () => ({tag: 'bar'}) })); const instance = preset({ foo: 'bar' }); const instance2 = newPreset({ some: 'some' });