@dxtmisha/wiki 0.24.3 → 0.39.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/package.json +8 -8
- package/src/classes/WikiStorybook.ts +92 -1
- package/src/classes/WikiStorybookItem.ts +79 -5
- package/src/classes/WikiStorybookProp.ts +109 -0
- package/src/library.ts +1 -0
- package/src/media/descriptions/wikiDescriptions.ts +32 -0
- package/src/media/descriptions/wikiDescriptionsAccordion.ts +204 -0
- package/src/media/descriptions/wikiDescriptionsActionSheet.ts +264 -0
- package/src/media/descriptions/wikiDescriptionsActions.ts +189 -0
- package/src/media/descriptions/wikiDescriptionsAnchor.ts +78 -0
- package/src/media/descriptions/wikiDescriptionsArrow.ts +214 -0
- package/src/media/descriptions/wikiDescriptionsBadge.ts +43 -0
- package/src/media/descriptions/wikiDescriptionsBars.ts +33 -0
- package/src/media/descriptions/wikiDescriptionsBlock.ts +159 -0
- package/src/media/descriptions/wikiDescriptionsButton.ts +32 -1
- package/src/media/descriptions/wikiDescriptionsCell.ts +26 -1
- package/src/media/descriptions/wikiDescriptionsChip.ts +42 -0
- package/src/media/descriptions/wikiDescriptionsChipGroup.ts +199 -0
- package/src/media/descriptions/wikiDescriptionsDialog.ts +226 -0
- package/src/media/descriptions/wikiDescriptionsField.ts +57 -2
- package/src/media/descriptions/wikiDescriptionsFieldCounter.ts +32 -0
- package/src/media/descriptions/wikiDescriptionsFieldLabel.ts +22 -0
- package/src/media/descriptions/wikiDescriptionsFieldMessage.ts +25 -0
- package/src/media/descriptions/wikiDescriptionsIcon.ts +46 -8
- package/src/media/descriptions/wikiDescriptionsImage.ts +91 -7
- package/src/media/descriptions/wikiDescriptionsInput.ts +313 -0
- package/src/media/descriptions/wikiDescriptionsList.ts +31 -0
- package/src/media/descriptions/wikiDescriptionsListGroup.ts +57 -0
- package/src/media/descriptions/wikiDescriptionsListItem.ts +42 -0
- package/src/media/descriptions/wikiDescriptionsListMenu.ts +41 -0
- package/src/media/descriptions/wikiDescriptionsMask.ts +42 -0
- package/src/media/descriptions/wikiDescriptionsMenu.ts +179 -0
- package/src/media/descriptions/wikiDescriptionsModal.ts +200 -0
- package/src/media/descriptions/wikiDescriptionsMotionTransform.ts +59 -6
- package/src/media/descriptions/wikiDescriptionsPage.ts +155 -0
- package/src/media/descriptions/wikiDescriptionsProgress.ts +39 -0
- package/src/media/descriptions/wikiDescriptionsRipple.ts +42 -3
- package/src/media/descriptions/wikiDescriptionsScrollbar.ts +48 -0
- package/src/media/descriptions/wikiDescriptionsSection.ts +152 -0
- package/src/media/descriptions/wikiDescriptionsSelect.ts +253 -0
- package/src/media/descriptions/wikiDescriptionsSelectValue.ts +107 -0
- package/src/media/descriptions/wikiDescriptionsSkeleton.ts +42 -1
- package/src/media/descriptions/wikiDescriptionsTextareaAutosize.ts +80 -0
- package/src/media/descriptions/wikiDescriptionsTooltip.ts +136 -0
- package/src/media/descriptions/wikiDescriptionsWindow.ts +60 -0
- package/src/media/functional/en/conversions.mdx +67 -0
- package/src/media/functional/en/dataUtils.mdx +25 -0
- package/src/media/functional/en/datetimeRef.mdx +1 -1
- package/src/media/functional/en/eventRef.mdx +1 -1
- package/src/media/functional/en/executionUtils.mdx +58 -0
- package/src/media/functional/en/geoFlagRef.mdx +1 -1
- package/src/media/functional/en/geoIntlRef.mdx +1 -1
- package/src/media/functional/en/geoRef.mdx +2 -2
- package/src/media/functional/en/meta.mdx +1206 -0
- package/src/media/functional/en/metaManager.mdx +376 -0
- package/src/media/functional/en/metaOg.mdx +694 -0
- package/src/media/functional/en/metaTwitter.mdx +853 -0
- package/src/media/functional/en/reactive.mdx +40 -0
- package/src/media/functional/en/refTypes.mdx +1 -1
- package/src/media/functional/en/useApiRef.mdx +5 -5
- package/src/media/functional/en/useMeta.mdx +431 -0
- package/src/media/functional/en/validationUtils.mdx +11 -0
- package/src/media/functional/functional-basic/functions/getCurrentDate/getCurrentDate.en.mdx +25 -0
- package/src/media/functional/functional-basic/functions/getCurrentDate/getCurrentDate.ru.mdx +25 -0
- package/src/media/functional/functional-basic/functions/getCurrentDate/getCurrentDate.vi.mdx +25 -0
- package/src/media/functional/functional-basic/functions/isEnter/isEnter.en.mdx +30 -0
- package/src/media/functional/functional-basic/functions/isEnter/isEnter.ru.mdx +30 -0
- package/src/media/functional/functional-basic/functions/isEnter/isEnter.vi.mdx +30 -0
- package/src/media/functional/ru/conversions.mdx +67 -0
- package/src/media/functional/ru/dataUtils.mdx +25 -0
- package/src/media/functional/ru/datetimeRef.mdx +2 -2
- package/src/media/functional/ru/eventRef.mdx +1 -1
- package/src/media/functional/ru/executionUtils.mdx +58 -0
- package/src/media/functional/ru/geoFlagRef.mdx +1 -1
- package/src/media/functional/ru/geoIntl.mdx +2 -2
- package/src/media/functional/ru/geoIntlRef.mdx +1 -1
- package/src/media/functional/ru/geoRef.mdx +2 -2
- package/src/media/functional/ru/listTypes.mdx +1 -1
- package/src/media/functional/ru/meta.mdx +1330 -0
- package/src/media/functional/ru/metaManager.mdx +376 -0
- package/src/media/functional/ru/metaOg.mdx +694 -0
- package/src/media/functional/ru/metaTwitter.mdx +853 -0
- package/src/media/functional/ru/reactive.mdx +40 -0
- package/src/media/functional/ru/refTypes.mdx +2 -2
- package/src/media/functional/ru/useApiRef.mdx +5 -5
- package/src/media/functional/ru/useMeta.mdx +431 -0
- package/src/media/functional/ru/validationUtils.mdx +11 -0
- package/src/media/mdx/Accordion/accordion.en.mdx +59 -0
- package/src/media/mdx/Accordion/accordion.ru.mdx +59 -0
- package/src/media/mdx/Accordion/slots.en.mdx +6 -0
- package/src/media/mdx/Accordion/slots.ru.mdx +6 -0
- package/src/media/mdx/Accordion/wikiMdxAccordion.ts +25 -0
- package/src/media/mdx/ActionSheet/actionSheet.en.mdx +61 -0
- package/src/media/mdx/ActionSheet/actionSheet.ru.mdx +61 -0
- package/src/media/mdx/ActionSheet/touchClose.en.mdx +21 -0
- package/src/media/mdx/ActionSheet/touchClose.ru.mdx +21 -0
- package/src/media/mdx/ActionSheet/wikiMdxActionSheet.ts +25 -0
- package/src/media/mdx/Actions/actions.en.mdx +48 -0
- package/src/media/mdx/Actions/actions.ru.mdx +48 -0
- package/src/media/mdx/Actions/flexible.en.mdx +19 -0
- package/src/media/mdx/Actions/flexible.ru.mdx +19 -0
- package/src/media/mdx/Actions/list.en.mdx +50 -0
- package/src/media/mdx/Actions/list.ru.mdx +50 -0
- package/src/media/mdx/Actions/wikiMdxActions.ts +31 -0
- package/src/media/mdx/Anchor/anchor.en.mdx +34 -0
- package/src/media/mdx/Anchor/anchor.ru.mdx +34 -0
- package/src/media/mdx/Anchor/expose.go.en.mdx +6 -0
- package/src/media/mdx/Anchor/expose.go.ru.mdx +6 -0
- package/src/media/mdx/Anchor/hide.en.mdx +28 -0
- package/src/media/mdx/Anchor/hide.ru.mdx +28 -0
- package/src/media/mdx/Anchor/isCopy.en.mdx +23 -0
- package/src/media/mdx/Anchor/isCopy.ru.mdx +23 -0
- package/src/media/mdx/Anchor/scroll.en.mdx +34 -0
- package/src/media/mdx/Anchor/scroll.ru.mdx +35 -0
- package/src/media/mdx/Anchor/wikiMdxAnchor.ts +43 -0
- package/src/media/mdx/Arrow/arrow.en.mdx +33 -0
- package/src/media/mdx/Arrow/arrow.ru.mdx +33 -0
- package/src/media/mdx/Arrow/wikiMdxArrow.ts +19 -0
- package/src/media/mdx/Block/block.en.mdx +42 -0
- package/src/media/mdx/Block/block.ru.mdx +42 -0
- package/src/media/mdx/Block/wikiMdxBlock.ts +19 -0
- package/src/media/mdx/ChipGroup/chipGroup.en.mdx +51 -0
- package/src/media/mdx/ChipGroup/chipGroup.ru.mdx +51 -0
- package/src/media/mdx/ChipGroup/selected.en.mdx +50 -0
- package/src/media/mdx/ChipGroup/selected.ru.mdx +50 -0
- package/src/media/mdx/ChipGroup/wikiMdxChipGroup.ts +25 -0
- package/src/media/mdx/Dialog/buttons.en.mdx +45 -0
- package/src/media/mdx/Dialog/buttons.ru.mdx +45 -0
- package/src/media/mdx/Dialog/dialog.en.mdx +66 -0
- package/src/media/mdx/Dialog/dialog.ru.mdx +65 -0
- package/src/media/mdx/Dialog/events.en.mdx +63 -0
- package/src/media/mdx/Dialog/events.ru.mdx +63 -0
- package/src/media/mdx/Dialog/states.en.mdx +58 -0
- package/src/media/mdx/Dialog/states.ru.mdx +57 -0
- package/src/media/mdx/Dialog/wikiMdxDialog.ts +37 -0
- package/src/media/mdx/Field/arrows.en.mdx +22 -6
- package/src/media/mdx/Field/arrows.ru.mdx +22 -6
- package/src/media/mdx/Field/slots.en.mdx +0 -13
- package/src/media/mdx/Field/slots.ru.mdx +0 -13
- package/src/media/mdx/Image/flag.en.mdx +23 -0
- package/src/media/mdx/Image/flag.ru.mdx +23 -0
- package/src/media/mdx/Image/image.en.mdx +26 -21
- package/src/media/mdx/Image/image.ru.mdx +26 -22
- package/src/media/mdx/Image/img-tag.en.mdx +105 -0
- package/src/media/mdx/Image/img-tag.ru.mdx +105 -0
- package/src/media/mdx/Image/wikiMdxImage.ts +12 -0
- package/src/media/mdx/Input/currency.en.mdx +38 -0
- package/src/media/mdx/Input/currency.ru.mdx +38 -0
- package/src/media/mdx/Input/date.en.mdx +53 -0
- package/src/media/mdx/Input/date.ru.mdx +53 -0
- package/src/media/mdx/Input/input.en.mdx +143 -0
- package/src/media/mdx/Input/input.ru.mdx +71 -0
- package/src/media/mdx/Input/mask.en.mdx +30 -0
- package/src/media/mdx/Input/mask.ru.mdx +30 -0
- package/src/media/mdx/Input/number.en.mdx +41 -0
- package/src/media/mdx/Input/number.ru.mdx +41 -0
- package/src/media/mdx/Input/type.en.mdx +26 -0
- package/src/media/mdx/Input/type.ru.mdx +26 -0
- package/src/media/mdx/Input/wikiMdxInput.ts +49 -0
- package/src/media/mdx/Menu/event.updateValue.en.mdx +29 -0
- package/src/media/mdx/Menu/event.updateValue.ru.mdx +30 -0
- package/src/media/mdx/Menu/expose.navigation.en.mdx +12 -0
- package/src/media/mdx/Menu/expose.navigation.ru.mdx +12 -0
- package/src/media/mdx/Menu/navigation.en.mdx +56 -0
- package/src/media/mdx/Menu/navigation.ru.mdx +56 -0
- package/src/media/mdx/Menu/slots.control.en.mdx +65 -0
- package/src/media/mdx/Menu/slots.control.ru.mdx +65 -0
- package/src/media/mdx/Menu/slots.en.mdx +2 -24
- package/src/media/mdx/Menu/slots.ru.mdx +2 -24
- package/src/media/mdx/Menu/wikiMdxMenu.ts +27 -3
- package/src/media/mdx/Modal/differences.en.mdx +130 -0
- package/src/media/mdx/Modal/differences.ru.mdx +65 -0
- package/src/media/mdx/Modal/modal.en.mdx +63 -0
- package/src/media/mdx/Modal/modal.ru.mdx +63 -0
- package/src/media/mdx/Modal/wikiMdxModal.ts +25 -0
- package/src/media/mdx/MotionTransform/expose.motionTransformElement.en.mdx +13 -0
- package/src/media/mdx/MotionTransform/expose.motionTransformElement.ru.mdx +14 -0
- package/src/media/mdx/MotionTransform/wikiMdxMotionTransform.ts +6 -0
- package/src/media/mdx/Page/page.en.mdx +38 -0
- package/src/media/mdx/Page/page.ru.mdx +38 -0
- package/src/media/mdx/Page/wikiMdxPage.ts +19 -0
- package/src/media/mdx/Section/section.en.mdx +38 -0
- package/src/media/mdx/Section/section.ru.mdx +38 -0
- package/src/media/mdx/Section/wikiMdxSection.ts +19 -0
- package/src/media/mdx/Select/select.en.mdx +69 -0
- package/src/media/mdx/Select/select.ru.mdx +69 -0
- package/src/media/mdx/Select/wikiMdxSelect.ts +19 -0
- package/src/media/mdx/SelectValue/selectValue.en.mdx +64 -0
- package/src/media/mdx/SelectValue/selectValue.ru.mdx +64 -0
- package/src/media/mdx/SelectValue/wikiMdxSelectValue.ts +19 -0
- package/src/media/mdx/TextareaAutosize/textarea-autosize.en.mdx +65 -0
- package/src/media/mdx/TextareaAutosize/textarea-autosize.ru.mdx +65 -0
- package/src/media/mdx/TextareaAutosize/wikiMdxTextareaAutosize.ts +19 -0
- package/src/media/mdx/Tooltip/event.tooltip.en.mdx +7 -0
- package/src/media/mdx/Tooltip/event.tooltip.ru.mdx +8 -0
- package/src/media/mdx/Tooltip/slot.control.en.mdx +14 -0
- package/src/media/mdx/Tooltip/slot.control.ru.mdx +14 -0
- package/src/media/mdx/Tooltip/tooltip.en.mdx +34 -0
- package/src/media/mdx/Tooltip/tooltip.ru.mdx +34 -0
- package/src/media/mdx/Tooltip/wikiMdxTooltip.ts +31 -0
- package/src/media/mdx/Window/classes.ru.mdx +1 -1
- package/src/media/mdx/event/events.actions.en.mdx +44 -0
- package/src/media/mdx/event/events.actions.ru.mdx +44 -0
- package/src/media/mdx/event/events.inputStandard.en.mdx +6 -0
- package/src/media/mdx/event/events.inputStandard.ru.mdx +6 -0
- package/src/media/mdx/event/wikiMdxEvent.ts +20 -8
- package/src/media/mdx/expose/expose.clear.en.mdx +1 -1
- package/src/media/mdx/expose/expose.descriptionId.en.mdx +6 -0
- package/src/media/mdx/expose/expose.descriptionId.ru.mdx +6 -0
- package/src/media/mdx/expose/expose.id.en.mdx +6 -0
- package/src/media/mdx/expose/expose.id.ru.mdx +6 -0
- package/src/media/mdx/expose/expose.labelId.en.mdx +6 -0
- package/src/media/mdx/expose/expose.labelId.ru.mdx +6 -0
- package/src/media/mdx/expose/wikiMdxExpose.ts +18 -0
- package/src/media/mdx/slot/body.en.mdx +6 -0
- package/src/media/mdx/slot/body.ru.mdx +6 -0
- package/src/media/mdx/slot/headline.en.mdx +7 -0
- package/src/media/mdx/slot/headline.ru.mdx +6 -0
- package/src/media/mdx/slot/leading.en.mdx +7 -0
- package/src/media/mdx/slot/leading.ru.mdx +7 -0
- package/src/media/mdx/slot/secondary.en.mdx +5 -0
- package/src/media/mdx/slot/secondary.ru.mdx +5 -0
- package/src/media/mdx/slot/trailing.en.mdx +7 -0
- package/src/media/mdx/slot/trailing.ru.mdx +7 -0
- package/src/media/mdx/slot/wikiMdxSlot.ts +30 -0
- package/src/media/mdx/style/isSkeleton.en.mdx +2 -2
- package/src/media/mdx/style/isSkeleton.ru.mdx +2 -2
- package/src/media/mdx/value/v-model-selected.en.mdx +28 -0
- package/src/media/mdx/value/v-model-selected.ru.mdx +28 -0
- package/src/media/mdx/value/v-model.en.mdx +26 -0
- package/src/media/mdx/value/v-model.ru.mdx +26 -0
- package/src/media/mdx/value/wikiMdxValue.ts +24 -3
- package/src/media/mdx/wikiMdx.ts +33 -1
- package/src/media/props/wiki.ts +44 -0
- package/src/media/props/wikiActions.ts +43 -0
- package/src/media/props/wikiActionsInclude.ts +62 -0
- package/src/media/props/wikiAnchor.ts +85 -0
- package/src/media/props/wikiAria.ts +123 -0
- package/src/media/props/wikiArrow.ts +24 -0
- package/src/media/props/wikiArrowInclude.ts +45 -0
- package/src/media/props/wikiAttributes.ts +143 -0
- package/src/media/props/wikiBadge.ts +7 -4
- package/src/media/props/wikiBars.ts +7 -6
- package/src/media/props/wikiBarsInclude.ts +82 -0
- package/src/media/props/wikiButton.ts +8 -4
- package/src/media/props/wikiChip.ts +4 -2
- package/src/media/props/wikiChipGroup.ts +39 -0
- package/src/media/props/wikiDialog.ts +33 -0
- package/src/media/props/wikiField.ts +18 -31
- package/src/media/props/wikiFieldCounterInclude.ts +87 -0
- package/src/media/props/wikiForm.ts +267 -0
- package/src/media/props/wikiHook.ts +20 -0
- package/src/media/props/wikiIcon.ts +19 -6
- package/src/media/props/wikiIconInclude.ts +322 -0
- package/src/media/props/wikiImage.ts +97 -20
- package/src/media/props/wikiInformation.ts +164 -0
- package/src/media/props/wikiInput.ts +34 -0
- package/src/media/props/wikiList.ts +10 -4
- package/src/media/props/wikiListItem.ts +23 -2
- package/src/media/props/wikiMask.ts +2 -12
- package/src/media/props/wikiMaskInclude.ts +54 -0
- package/src/media/props/wikiMenu.ts +1 -11
- package/src/media/props/wikiMotionTransform.ts +7 -13
- package/src/media/props/wikiOption.ts +356 -0
- package/src/media/props/wikiProgress.ts +8 -5
- package/src/media/props/wikiScrollbar.ts +6 -6
- package/src/media/props/wikiSelect.ts +68 -0
- package/src/media/props/wikiSelectValue.ts +30 -0
- package/src/media/props/wikiStatus.ts +34 -57
- package/src/media/props/wikiStyle.ts +85 -406
- package/src/media/props/wikiTechnical.ts +141 -1
- package/src/media/props/wikiText.ts +167 -0
- package/src/media/props/wikiTooltip.ts +53 -0
- package/src/media/props/wikiValue.ts +22 -276
- package/src/media/props/wikiWindow.ts +24 -45
- package/src/shims-mdx.d.ts +5 -0
- package/src/styles/storybookStyle.scss +3 -1
- package/src/types/storybookTypes.ts +48 -4
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import {Meta} from '@storybook/addon-docs/blocks'
|
|
2
|
+
|
|
3
|
+
<Meta title='@dxtmisha/functional/en/Classes/MetaManager'/>
|
|
4
|
+
|
|
5
|
+
# MetaManager Class
|
|
6
|
+
|
|
7
|
+
A class for working with HTML meta tags with automatic DOM synchronization and safe attribute encoding. Provides reading, updating, and generating meta tags for SEO optimization and social media integration (Open Graph, Twitter Cards).
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
- **DOM Synchronization** — automatic meta tag updates in document head
|
|
12
|
+
- **Dual Format Support** — works with both `name` and `property` attributes
|
|
13
|
+
- **HTML Generation** — converts meta tags to HTML strings for server-side rendering
|
|
14
|
+
- **Safe Encoding** — automatic escaping of special characters in attributes
|
|
15
|
+
- **Type Safety** — TypeScript support with generics for type definitions
|
|
16
|
+
- **Flexible API** — chainable methods for convenient usage
|
|
17
|
+
- **SSR Compatible** — works in both browser and server environments
|
|
18
|
+
- **Auto-initialization** — reads existing meta tags from DOM on construction
|
|
19
|
+
|
|
20
|
+
## Constructor
|
|
21
|
+
|
|
22
|
+
### `constructor`
|
|
23
|
+
|
|
24
|
+
Creates a MetaManager instance with specified parameters and automatically reads current meta tags from DOM.
|
|
25
|
+
|
|
26
|
+
**Parameters:**
|
|
27
|
+
- `listMeta: string[]` — list of meta tag names to manage
|
|
28
|
+
- `isProperty?: boolean` — use `property` attribute instead of `name` (default: `false`)
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
import { MetaManager } from '@dxtmisha/functional'
|
|
32
|
+
|
|
33
|
+
// Standard meta tags (name attribute)
|
|
34
|
+
const meta = new MetaManager([
|
|
35
|
+
'description',
|
|
36
|
+
'keywords',
|
|
37
|
+
'author'
|
|
38
|
+
])
|
|
39
|
+
|
|
40
|
+
// Open Graph meta tags (property attribute)
|
|
41
|
+
const ogMeta = new MetaManager([
|
|
42
|
+
'og:title',
|
|
43
|
+
'og:description',
|
|
44
|
+
'og:image',
|
|
45
|
+
'og:url'
|
|
46
|
+
], true)
|
|
47
|
+
|
|
48
|
+
// Twitter Cards
|
|
49
|
+
const twitterMeta = new MetaManager([
|
|
50
|
+
'twitter:card',
|
|
51
|
+
'twitter:title',
|
|
52
|
+
'twitter:description',
|
|
53
|
+
'twitter:image'
|
|
54
|
+
])
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Data Query Methods
|
|
58
|
+
|
|
59
|
+
### `getListMeta`
|
|
60
|
+
|
|
61
|
+
Returns the list of meta tag names being managed.
|
|
62
|
+
|
|
63
|
+
**Returns:** `string[]` — array of meta tag names
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
const meta = new MetaManager(['description', 'keywords', 'author'])
|
|
67
|
+
|
|
68
|
+
const names = meta.getListMeta()
|
|
69
|
+
// ['description', 'keywords', 'author']
|
|
70
|
+
|
|
71
|
+
// Check if tag is managed
|
|
72
|
+
const isManaged = names.includes('description') // true
|
|
73
|
+
|
|
74
|
+
// Iterate managed tags
|
|
75
|
+
names.forEach(name => {
|
|
76
|
+
console.log(`Managing: ${name}`)
|
|
77
|
+
})
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### `getItem`
|
|
81
|
+
|
|
82
|
+
Gets the content of a meta tag by name from internal storage.
|
|
83
|
+
|
|
84
|
+
**Parameters:**
|
|
85
|
+
- `name: string` — meta tag name
|
|
86
|
+
|
|
87
|
+
**Returns:** `string` — meta tag content (empty string if not set)
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
const meta = new MetaManager(['description', 'keywords', 'author'])
|
|
91
|
+
|
|
92
|
+
// Get meta description
|
|
93
|
+
const description = meta.get('description')
|
|
94
|
+
|
|
95
|
+
// Get keywords
|
|
96
|
+
const keywords = meta.get('keywords')
|
|
97
|
+
|
|
98
|
+
// Non-existent tag returns empty string
|
|
99
|
+
const missing = meta.get('non-existent') // ''
|
|
100
|
+
|
|
101
|
+
// Use in conditions
|
|
102
|
+
if (meta.get('description')) {
|
|
103
|
+
console.log('Description is set')
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### `getItems`
|
|
108
|
+
|
|
109
|
+
Returns all meta tags as an object.
|
|
110
|
+
|
|
111
|
+
**Returns:** `Record<string, string | undefined>` — object with all meta tags
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
const meta = new MetaManager(['description', 'keywords', 'author'])
|
|
115
|
+
|
|
116
|
+
const allMeta = meta.getItems()
|
|
117
|
+
// { description: '...', keywords: '...', author: '...' }
|
|
118
|
+
|
|
119
|
+
// Check all meta tags
|
|
120
|
+
Object.keys(allMeta).forEach(key => {
|
|
121
|
+
console.log(`${key}: ${allMeta[key]}`)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
// Use in validation
|
|
125
|
+
const hasAllTags = Object.values(allMeta).every(value => value !== '')
|
|
126
|
+
|
|
127
|
+
// Export for logging
|
|
128
|
+
console.log('Current meta state:', allMeta)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Data Management Methods
|
|
132
|
+
|
|
133
|
+
### `set`
|
|
134
|
+
|
|
135
|
+
Sets the content of a meta tag in internal storage and updates or creates the corresponding meta element in DOM.
|
|
136
|
+
|
|
137
|
+
**Parameters:**
|
|
138
|
+
- `name: string` — meta tag name
|
|
139
|
+
- `content: string` — meta tag content
|
|
140
|
+
|
|
141
|
+
**Returns:** `this` — for method chaining
|
|
142
|
+
|
|
143
|
+
```javascript
|
|
144
|
+
const meta = new MetaManager(['description', 'keywords', 'author'])
|
|
145
|
+
|
|
146
|
+
// Set single meta tag
|
|
147
|
+
meta.set('description', 'Website description')
|
|
148
|
+
|
|
149
|
+
// Chain multiple updates
|
|
150
|
+
meta
|
|
151
|
+
.set('description', 'My awesome website')
|
|
152
|
+
.set('keywords', 'web, development, javascript')
|
|
153
|
+
.set('author', 'John Doe')
|
|
154
|
+
|
|
155
|
+
// Dynamic update
|
|
156
|
+
const updateSEO = (pageData) => {
|
|
157
|
+
meta
|
|
158
|
+
.set('description', pageData.description)
|
|
159
|
+
.set('keywords', pageData.keywords)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Remove meta tag
|
|
163
|
+
meta.set('temporary', '')
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### `setByList`
|
|
167
|
+
|
|
168
|
+
Sets multiple meta tags from an object.
|
|
169
|
+
|
|
170
|
+
**Parameters:**
|
|
171
|
+
- `metaList: Record<string, string | undefined>` — object with meta tag names and content
|
|
172
|
+
|
|
173
|
+
**Returns:** `this` — for method chaining
|
|
174
|
+
|
|
175
|
+
```javascript
|
|
176
|
+
const meta = new MetaManager(['description', 'keywords', 'author'])
|
|
177
|
+
|
|
178
|
+
// Set multiple tags at once
|
|
179
|
+
meta.setByList({
|
|
180
|
+
description: 'My awesome website',
|
|
181
|
+
keywords: 'web, development, javascript',
|
|
182
|
+
author: 'John Doe'
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
// Dynamic page updates
|
|
186
|
+
const updatePageMeta = (page) => {
|
|
187
|
+
meta.setByList(page.meta)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// From API response
|
|
191
|
+
fetch('/api/page-meta')
|
|
192
|
+
.then(res => res.json())
|
|
193
|
+
.then(data => meta.setByList(data))
|
|
194
|
+
|
|
195
|
+
// Partial updates
|
|
196
|
+
meta.setByList({
|
|
197
|
+
description: 'Updated description'
|
|
198
|
+
// Other tags remain unchanged
|
|
199
|
+
})
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### `html`
|
|
203
|
+
|
|
204
|
+
Returns all meta tags as an HTML string with safe attribute encoding. Useful for server-side rendering.
|
|
205
|
+
|
|
206
|
+
**Returns:** `string` — HTML string with meta tags
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
const meta = new MetaManager(['description', 'keywords', 'author'])
|
|
210
|
+
|
|
211
|
+
meta.setByList({
|
|
212
|
+
description: 'My website with "quotes" & special chars',
|
|
213
|
+
keywords: 'web, javascript',
|
|
214
|
+
author: 'John Doe'
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
const htmlString = meta.html()
|
|
218
|
+
// <meta name="description" content="My website with "quotes" & special chars">
|
|
219
|
+
// <meta name="keywords" content="web, javascript">
|
|
220
|
+
// <meta name="author" content="John Doe">
|
|
221
|
+
|
|
222
|
+
// Use in SSR templates
|
|
223
|
+
const htmlTemplate = `
|
|
224
|
+
<!DOCTYPE html>
|
|
225
|
+
<html>
|
|
226
|
+
<head>
|
|
227
|
+
${meta.html()}
|
|
228
|
+
<title>Page Title</title>
|
|
229
|
+
</head>
|
|
230
|
+
<body>...</body>
|
|
231
|
+
</html>
|
|
232
|
+
`
|
|
233
|
+
|
|
234
|
+
// Express.js example
|
|
235
|
+
app.get('/page', (req, res) => {
|
|
236
|
+
const meta = new MetaManager(['description', 'keywords'])
|
|
237
|
+
meta.setByList(req.pageData.meta)
|
|
238
|
+
|
|
239
|
+
res.send(`
|
|
240
|
+
<html>
|
|
241
|
+
<head>${meta.html()}</head>
|
|
242
|
+
<body>...</body>
|
|
243
|
+
</html>
|
|
244
|
+
`)
|
|
245
|
+
})
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Practical Examples
|
|
249
|
+
|
|
250
|
+
### SEO Management
|
|
251
|
+
|
|
252
|
+
```javascript
|
|
253
|
+
const seoMeta = new MetaManager([
|
|
254
|
+
'description',
|
|
255
|
+
'keywords',
|
|
256
|
+
'author',
|
|
257
|
+
'robots',
|
|
258
|
+
'viewport'
|
|
259
|
+
])
|
|
260
|
+
|
|
261
|
+
// Set SEO tags
|
|
262
|
+
seoMeta.setByList({
|
|
263
|
+
description: 'Complete guide to web development',
|
|
264
|
+
keywords: 'web, html, css, javascript, tutorial',
|
|
265
|
+
author: 'WebDev Team',
|
|
266
|
+
robots: 'index, follow',
|
|
267
|
+
viewport: 'width=device-width, initial-scale=1.0'
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
// Update on route change
|
|
271
|
+
router.on('change', (route) => {
|
|
272
|
+
seoMeta.setByList(route.meta)
|
|
273
|
+
})
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Open Graph Integration
|
|
277
|
+
|
|
278
|
+
```javascript
|
|
279
|
+
const ogMeta = new MetaManager([
|
|
280
|
+
'og:title',
|
|
281
|
+
'og:description',
|
|
282
|
+
'og:image',
|
|
283
|
+
'og:url',
|
|
284
|
+
'og:type',
|
|
285
|
+
'og:site_name'
|
|
286
|
+
], true)
|
|
287
|
+
|
|
288
|
+
// Set Open Graph data
|
|
289
|
+
ogMeta.setByList({
|
|
290
|
+
'og:title': 'Amazing Article Title',
|
|
291
|
+
'og:description': 'This article will blow your mind',
|
|
292
|
+
'og:image': 'https://example.com/image.jpg',
|
|
293
|
+
'og:url': 'https://example.com/article',
|
|
294
|
+
'og:type': 'article',
|
|
295
|
+
'og:site_name': 'My Website'
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
// For social media sharing
|
|
299
|
+
const shareData = {
|
|
300
|
+
title: ogMeta.get('og:title'),
|
|
301
|
+
description: ogMeta.get('og:description'),
|
|
302
|
+
image: ogMeta.get('og:image')
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Multi-Platform Meta Management
|
|
307
|
+
|
|
308
|
+
```javascript
|
|
309
|
+
// Create managers for different platforms
|
|
310
|
+
const standardMeta = new MetaManager(['description', 'keywords'])
|
|
311
|
+
const ogMeta = new MetaManager(['og:title', 'og:description', 'og:image'], true)
|
|
312
|
+
const twitterMeta = new MetaManager(['twitter:card', 'twitter:title', 'twitter:description'])
|
|
313
|
+
|
|
314
|
+
// Update all platforms
|
|
315
|
+
const updateAllMeta = (data) => {
|
|
316
|
+
standardMeta.setByList({
|
|
317
|
+
description: data.description,
|
|
318
|
+
keywords: data.keywords
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
ogMeta.setByList({
|
|
322
|
+
'og:title': data.title,
|
|
323
|
+
'og:description': data.description,
|
|
324
|
+
'og:image': data.image
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
twitterMeta.setByList({
|
|
328
|
+
'twitter:card': 'summary_large_image',
|
|
329
|
+
'twitter:title': data.title,
|
|
330
|
+
'twitter:description': data.description
|
|
331
|
+
})
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Generate combined HTML for SSR
|
|
335
|
+
const allMetaHTML = [
|
|
336
|
+
standardMeta.html(),
|
|
337
|
+
ogMeta.html(),
|
|
338
|
+
twitterMeta.html()
|
|
339
|
+
].join('')
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Dynamic Page Updates
|
|
343
|
+
|
|
344
|
+
```javascript
|
|
345
|
+
const meta = new MetaManager(['description', 'keywords'])
|
|
346
|
+
|
|
347
|
+
// Single Page Application
|
|
348
|
+
const loadPage = async (pageId) => {
|
|
349
|
+
const pageData = await fetch(`/api/pages/${pageId}`).then(r => r.json())
|
|
350
|
+
|
|
351
|
+
// Update meta tags
|
|
352
|
+
meta.setByList(pageData.meta)
|
|
353
|
+
|
|
354
|
+
// Update title
|
|
355
|
+
document.title = pageData.title
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// React/Vue integration
|
|
359
|
+
useEffect(() => {
|
|
360
|
+
meta.set('description', page.description)
|
|
361
|
+
return () => {
|
|
362
|
+
// Cleanup if needed
|
|
363
|
+
meta.set('description', '')
|
|
364
|
+
}
|
|
365
|
+
}, [page])
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
## Notes
|
|
369
|
+
|
|
370
|
+
- The constructor automatically reads existing meta tags from DOM using the `update()` method
|
|
371
|
+
- Methods that modify DOM check runtime environment with `isDomRuntime()` before accessing `document`
|
|
372
|
+
- The `html()` method uses `encodeAttribute()` function to prevent XSS issues when injecting into SSR templates
|
|
373
|
+
- Special characters in content are automatically escaped: `"` → `"`, `&` → `&`, etc.
|
|
374
|
+
- When a meta tag doesn't exist in DOM, `set()` creates it in `document.head`
|
|
375
|
+
- Empty strings are valid values and will update the meta tag content to empty
|
|
376
|
+
- The class works seamlessly in both browser and Node.js (SSR) environments
|